[AccessD] OT: Friday Puzzles

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Sat Apr 24 10:29:38 CDT 2010


8925 medals.

Correct?

x = size of the army
y = qty of soldiers who have lost one arm, one leg, one ear and one eye;

y = 0.85*(1-0.8)*0.75*0.7x

Assuming that army size is between 100,000+ and 150,000
(
http://www.secondworldwar.co.uk/units.html
http://usmilitary.about.com/od/army/l/blchancommand.htm
)

the anwers would be

foreach (int x in Enumerable.Range(100000,50001))
{
    decimal y = 0.85m * (1.0m-0.8m) * 0.75m * 0.7m * x;

    if (y == (decimal)(int)y)
        Console.WriteLine("// SizeOfTheArmy={0:#,0}+, Medals={1} ", 
            x, (decimal)(int)y); 
}

// SizeOfTheArmy=100,000+, Medals=8925
// SizeOfTheArmy=104,000+, Medals=9282
// SizeOfTheArmy=108,000+, Medals=9639
// SizeOfTheArmy=112,000+, Medals=9996
// SizeOfTheArmy=116,000+, Medals=10353
// SizeOfTheArmy=120,000+, Medals=10710
// SizeOfTheArmy=124,000+, Medals=11067
// SizeOfTheArmy=128,000+, Medals=11424
// SizeOfTheArmy=132,000+, Medals=11781
// SizeOfTheArmy=136,000+, Medals=12138
// SizeOfTheArmy=140,000+, Medals=12495
// SizeOfTheArmy=144,000+, Medals=12852
// SizeOfTheArmy=148,000+, Medals=13209

As we do not have the general's army size defined but we know that general
wanted to reward teh fewest number of soldiers then we select the minimal
appropriate army size = 100,000 soldiers, and then the answer will be 8925
medals.

Correct?

Thank you.

--Shamil


??????? ????????????? ????
http://www.apn-spb.ru/opinions/article6850.htm

.??? ??????, ??????? ????????: ????? ?????????? - ? ??????? ????? ??????... 

http://www.apn-spb.ru/opinions/article7197.htm 

http://www.apn-spb.ru/publications/article7223.htm


Thank you, Susan and Drew - your lovely chat (and Drew's original code)
forced me to try to find math based solution ;) - here it's (C#):

1) Using lambda expressions:

public static int GetSurvivorNumberUsingFPS(int arraySize)
{
    Func<int, int, int> survivorNumber = null;
    survivorNumber =
        (lineSize, power) =>
            Math.Pow(2, power) > lineSize / 2 ?
            (int)Math.Pow(2, power) :
            survivorNumber(lineSize, power + 1);
    return survivorNumber(arraySize, 1);
}

2) Using iteration:

public static int GetSurvivorNumberUsingIteration(int arraySize)
{
    int power = 0;
    while (Math.Pow(2, ++power) <= arraySize / 2) ;
    return (int)Math.Pow(2, power); 
}

3) Using recursion:

public static int GetSurvivorNumberUsingRecursion(int arraySize, int power)
{
    if (Math.Pow(2, power) > arraySize / 2) 
        return (int)Math.Pow(2, power);
    return GetSurvivorNumberUsingRecursion(arraySize, power + 1);  
}

One can make similar iterative and recursive coding solutions using VBA.

Although C#'s/VB.NET's functional programming approach is more
powerful/scalable as modern compilers can compile, build and "automagically"
distribute execution of functional code blocks on several processor cores...

Thank you Arthur for this puzzle - it forced me to start learning C#
functional programming...

--Shamil

This is a sample of what called lambda expressions ((recursive) functional
programming) in C#/VB.NET.
It is really powerfull (declarative) programming technique/approach.
As one can imagine lambda expressions can be executed in parallel on several
processor cores

E:\DesignPatterns\VBA\Calculator.NET\VBNetCalculator\VBNetCalculator.sln

C:\Documents and Settings\Administrator\Application
Data\SMSConsulting\Access PowerTools 
2 Power n

a = arraySize
n = step #

(2>>n)*m

where m = 1,2,..., a/2

while (2>>n)<a/2


Add-In\

            return prefix +
Access.PowerTools.Utilities.Strings.EncodeObjectName(objectName);

500
250
125
63
32
16
8
4
2

8.925%?

0.85*0.2*0.75*0.7 = 0.08925

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller
Sent: Saturday, April 24, 2010 5:27 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] OT: Friday Puzzles

As many of you figured out, position 512 is the surviving position.

It's very interesting how many of you readers are so easily diverted from
what might have been productive work! I shall endeavour to come up with more
puzzles for you all.

It's also interesting that you all focused on the survivor problem. Everyone
seems to have ignored the other one.

Arthur
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list