Anonymous user
Find minimum number of coins that make a given value: Difference between revisions
Find minimum number of coins that make a given value (view source)
Revision as of 13:53, 9 August 2021
, 2 years ago→{{header|Nim}}
(Added Go) |
|||
Line 137:
(0, (1, 1))
</pre>
=={{header|Nim}}==
<lang Nim>import strformat
const
Coins = [200, 100, 50, 20, 10, 5, 2, 1]
Target = 988
echo &"Minimal number of coins to make a value of {Target}:"
var count = 0
var remaining = Target
for coin in Coins:
let n = remaining div coin
if n != 0:
inc count, n
echo &"coins of {coin:3}: {n}"
dec remaining, n * coin
if remaining == 0: break
echo "\nTotal: ", count</lang>
{{out}}
<pre>Minimal number of coins to make a value of 988:
coins of 200: 4
coins of 100: 1
coins of 50: 1
coins of 20: 1
coins of 10: 1
coins of 5: 1
coins of 2: 1
coins of 1: 1
Total: 11</pre>
=={{header|Phix}}==
|