Jump to content

Find minimum number of coins that make a given value: Difference between revisions

m
→‎{{header|Haskell}}: Case where smallest denomination leaves an unsummed residue
m (→‎{{header|Haskell}}: Case where smallest denomination leaves an unsummed residue)
Line 117:
change :: [Int] -> Int -> Either String [(Int, Int)]
change units n
| 10 `elem`== unitsmod n m = Right $ go (sortOn Down units) (abs n)
| otherwise = Left "Incomplete denominations - lacks 1"
Left $
concat
[ "Residue of ",
show (mod n m),
" - no denomination smaller than ",
show m,
"."
]
where
m = minimum units
go _ 0 = []
go (x : xs) n
Line 144 ⟶ 153:
qvs
)
(change [200, 100, 50, 20, 10, 5, 2, 1] n)</lang>
{{Out}}
<pre>Summing to 1024:
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.