RosettaCodeData/Task/Count-the-coins/Haskell/count-the-coins-2.hs
2023-07-01 13:44:08 -04:00

11 lines
310 B
Haskell

count :: Integral a => [Int] -> [a]
count = foldr addCoin (1 : repeat 0)
where
addCoin c oldlist = newlist
where
newlist = take c oldlist ++ zipWith (+) newlist (drop c oldlist)
main :: IO ()
main = do
print (count [25, 10, 5, 1] !! 100)
print (count [100, 50, 25, 10, 5, 1] !! 10000)