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 05:01, 9 August 2021
, 2 years ago→{{header|Julia}}
m (→{{header|REXX}}: added total coins paid-out, and a check if an exact pay-out isn't possible.) |
|||
Line 38:
=={{header|Julia}}==
=== Long version ===
Using a linear optimizer for this is serious overkill, but why not?
<lang julia>using JuMP, GLPK
Line 78 ⟶ 79:
Value of onehundreds is 1.0
Value of twohundreds is 4.0
</pre>
=== Brief REPL command version ===
<pre>
julia> accumulate((x, y) -> (x[1] % y, (y, x[1] ÷ y)), [200, 100, 50, 20, 10, 5, 2, 1], init=(988, 0))
8-element Vector{Tuple{Int64, Tuple{Int64, Int64}}}:
(188, (200, 4))
(88, (100, 1))
(38, (50, 1))
(18, (20, 1))
(8, (10, 1))
(3, (5, 1))
(1, (2, 1))
(0, (1, 1))
</pre>
|