Puzzle 8-10-08 (answer)
BCS
ao at pathlink.com
Mon Aug 11 11:07:06 PDT 2008
Reply to Steven,
> "BCS" wrote
>
>> Reply to wyverex,
>>
>>> The Abbott's Puzzle
>>>
>>> "If 100 bushels of corn were distributed among 100 people in such a
>>> manner that each man received three bushels, each woman two, and
>>> each child half a bushel, how many men, women, and children were
>>> there?"
>>>
>> <M, W, C> = <17,5,78> + i*<-3,5,-2> for i in [0,5]
>>
> You missed <20, 0, 80>
>
> Of course, this assumes that it's possible to have 0 women (unlikely
> :) )
>
> And what's with the non-D code? It should be a requirement that you
> have to solve it with D ;)
>
> -Steve
>
D can't do the closed form solution (and I can't remember how so I used excel)
how about a D vector solution (untested as I'm still running 1.033)
void main()
{
short[101] ramp;
foreach(i,ref j;ramp)j=i;
short[101][101] grain;
short[101][101] c;
foreach(short m, ref short[101] row; grain)
row[] = m*6 - 200 + ramp[]*4 + (100-m-ramp[])*1;
foreach(short m, ref short[101] row; c)
row[] = 100-m-ramp[];
for(int m = 0; m <= 100; m++)
for(int w = 0; w <= 100; w++)
if(c[m][w] >= 0 && grain[m][w] == 0)
writef("M=%d W=%d C=%d\n",m,w,c[m][w]);
}
More information about the Digitalmars-d-learn
mailing list