3 jealous brothers are to divvy up a set of commemorative coins.
There are an equal number of coins of each of the values: $1, $2, $3.
They discover that it is possible to do this in such a way that each brother gets a different assortment of coins, yet each gets the same number of coins and the same total value of coins.
What's the smallest possible number of coins in the set?
My reading of the problem was each brother got the the same value and the same number of coins but
a different assortment across the range, ie, I saw all values as being represented in a person's allocation.
That latter thought however is
not actually specified. If that in fact was intended then one needs to look down the list to the rows beginning with 9.
Charlie does have such a line in his output.
Charlie's program does also allow for zero denominations (If my variables counted from zero I'd have a comparative output differing only by program structure).
Person & Denomination
A B C
No|1 2 3| 1 2 3 |1 2 3 3 1 1 1 1 1 1 1 1 1 6 6 6
5 1 3 1 2 1 2 2 1 2 10 10 10
5 2 1 2 1 3 1 2 1 2 10 10 10
5 2 1 2 2 1 2 1 3 1 10 10 10
6 2 2 2 2 2 2 2 2 2 12 12 12
7 1 5 1 3 1 3 3 1 3 14 14 14
7 2 3 2 2 3 2 3 1 3 14 14 14
7 2 3 2 3 1 3 2 3 2 14 14 14
7 3 1 3 1 5 1 3 1 3 14 14 14
7 3 1 3 2 3 2 2 3 2 14 14 14
7 3 1 3 3 1 3 1 5 1 14 14 14
8 2 4 2 3 2 3 3 2 3 16 16 16
8 3 2 3 2 4 2 3 2 3 16 16 16
8 3 2 3 3 2 3 2 4 2 16 16 16
9 1 7 1 4 1 4 4 1 4 18 18 18
9 2 5 2 3 3 3 4 1 4 18 18 18 9 2 5 2 4 1 4 3 3 3 18 18 18
9 3 3 3 2 5 2 4 1 4 18 18 18
9 3 3 3 3 3 3 3 3 3 18 18 18
9 3 3 3 4 1 4 2 5 2 18 18 18
9 4 1 4 1 7 1 4 1 4 18 18 18
9 4 1 4 2 5 2 3 3 3 18 18 18
9 4 1 4 3 3 3 2 5 2 18 18 18
9 4 1 4 4 1 4 1 7 1 18 18 18
OPEN "c:\qb64\work\commems.txt" FOR OUTPUT AS #1
coins = 3
DO
FOR a = 1 TO coins
FOR b = 1 TO coins
FOR c = 1 TO coins
IF a + b + c = coins THEN
FOR d = 1 TO coins
FOR g = 1 TO coins
IF a + d + g = coins THEN
FOR e = 1 TO coins
FOR f = 1 TO coins
IF d + e + f = coins THEN
FOR h = 1 TO coins
IF b + e + h = coins THEN
FOR i = 1 TO coins
IF c + f + i = coins AND g + h + i = coins THEN
p1 = a + b * 2 + c * 3
p2 = d + e * 2 + f * 3
p3 = g + h * 2 + i * 3
IF p1 = p2 AND p1 = p3 AND p2 = p3 THEN
PRINT coins; a; b; c; d; e; f; g; h; i; p1; p2; p3
PRINT #1, coins; a; b; c; d; e; f; g; h; i; p1; p2; p3
END IF
END IF
NEXT i
END IF
NEXT h
END IF
NEXT f
NEXT e
END IF
NEXT g: NEXT d
END IF
NEXT c: NEXT b: NEXT a
coins = coins + 1
LOOP WHILE coins <> 10
CLOSE 1
|
Posted by brianjn
on 2013-02-06 19:45:05 |