Find minimum number of coins that make a given value
Find minimum number of coins that make a given value is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
- Find minimum number of coins that make a given value
coins = [1,2,5,10,20,50,100,200]
value = 988
Coins are:
4*200
1*100
1*50
1*20
1*10
1*5
1*2
1*1
Ring
<lang ring> load "stdlib.ring"
see "working..." + nl see "Coins are:" + nl sum = 988
sumCoins = 0 coins = [1,2,5,10,20,50,100,200] coins = reverse(coins)
for n = 1 to len(coins)
nr = floor(sum/coins[n]) if nr > 0 sumCoins= nr*coins[n] sum -= sumCoins see "" + nr + "*" + coins[n] + nl ok
next
see "done..." + nl </lang>
- Output:
working... Coins are: 4*200 1*100 1*50 1*20 1*10 1*5 1*2 1*1 done...