Contribution for Puzzlet #030
From: Denis Borris [borrisd@ca.inter.net]
Comments:
1: the "1p" need not be looped, reducing time tremendously
(every combo without the 1p includes the 1p by default)
2: the loops may be incremented by the coin values, eliminating the "summing"
This simple coding does it:
(f=50p, e=20p, d=10p, c=5p, b=2p, a=1p)
100 for f = 0 to 100 step 50
110 for e = 0 to 100-f step 20
120 for d = 0 to 100-f-e step 10
130 for c = 0 to 100-f-e-d step 5
140 for b = 0 to 100-f-e-d-c step 2
150 a=100-f-e-d-c-b 'only required if we want a detailed printout
160 count = count + 1
170 next b
180 next c
190 next d
200 next e
210 next f
220 print count
For a detailed printout (number, amount), insert:
155 print a,a,b/2,b,c/5,c,d/10,d,e/20,e,f/50,f
Thanks for the program. Very neat! I agree with your point that the 1p loop can be done away with. I'm going to include this as a contribution, with credit given to yourself.
Dave.
| Site design/maintenance: Dave Ellis | E-mail
me! |
Last Updated: February 22nd, 2004. |