I have a bag of 100 coins, containing penny, dime and half-dollar denominations. Total value is $5 (five dollars).
Write a program for our computers to find how many of each type of coin???
Solution of the Puzzle of the Month
We will assume the bag to contain x pennies, y dimes and z halfdollars.
There can not be less than 10 pennies (the total value of the bag would never come to an even $5). For the same reason, x can only increment by 10 and the maximum for x is 90.
The number of dimes is limited to 44 so as to leave room for 10 pennies and 1 half-dollar. And it would still not be a solution, since there would be only 55 coins to total $5!
In a similar reasoning, z can not be more than 9 and probably much less.
Thus we write the following program:
10 FOR X=10 TO 90 STEP 10
20 FOR Y=1 TO 44
30 FOR Z=1 TO 9
40 REM SUM: LET S=X+Y+Z
50 REM VALUE: LET V= X+10*Y+50*Z
60 IF S=100 AND V=500 THEN PRINT X;" PENNIES"';Y;" DIMES"';Z;" HALFDOLLARS"
70 NEXT Z
80 NEXT Y
90 NEXT X
100 STOP
In about a minute, your TS2068 will print the answer:
60 pennies = $0.60 39 dimes = $3.90 1 half$ = $0.50 ------------------- 100 coins = $5.00
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.