A rich uncle of Jack, John and Jim gave them some valuable coins in the ratio A:B:C respectively, where C≤B≤A<10. For example, if the ratio is 3:2:1 and there is a total of 36 coins, then Jack would get 18, John would get 12, and Jim would get 6. At first, he distributed the coins randomly among the three, but the ratio was not A:B:C. Jack returned a number of coins equal to the percentage that he was supposed to receive. So (using the same ratios) if he got 30 coins, he returned 15 (50%). John and Jim returned coins in a similar fashion. Uncle then divided all the returned coins equally among the three. Believe it or not, the coins each had after this ended up exactly A:B:C.
Tom: And that, Dick, is what happened. Uncle gave out the minimum number of coins possible for that ratio, and for this strange method of distribution.
Dick: How many coins did Uncle give out?
Tom: This many (shows him a number)
Dick: And how many did each nephew receive?
Tom: Figure it out yourself.
Dick: Ok, I need hints.
Tom: Only one of them received that number over here (points to a day in his calendar).
And before even seeing the number, Dick shouts "GOT IT!" How many coins did each receive?
The only possibility I found, and it doesn't need to consider the coversations:
2 1 1 ratios
20 4 4 orig distribution
50 25 25 percentages returned
10 3 3 result
14 7 7 after redistributing
14 7 7 final dist
for a=1:30
for b=1:a
if gcd(a,b)==1
for c=1:b
if gcd(a,c)==1 && gcd(b,c)==1
for m=1:15
reqDist=m*[a b c];
nCoins=sum(reqDist);
for a1=1:nCoins-2
for b1=1:nCoins-a1-1
c1=nCoins-a1-b1;
retPct=100*reqDist./sum(reqDist);
good=true;
for i=1:3
if retPct(i)~=floor(retPct)
good=false;
break
end
end
if good
new1=[a1 b1 c1]-retPct.*[a1 b1 c1]/100;
refund=nCoins-sum(new1);
if mod(refund,3)==0
new=new1+refund/3;
if isequal(new,reqDist)
disp([a b c])
disp([a1 b1 c1])
disp(retPct)
disp(new1)
disp(new)
disp(reqDist)
disp(' ')
end
end
end
end
end
end
end
end
end
end
end
|
Posted by Charlie
on 2024-03-08 13:26:28 |