DEV Community

loading...

Discussion on: Daily Challenge #262 - No One Likes Spare Change

Collapse
aminnairi profile image
Amin • Edited

Haskell

import Data.List (sort)


minimumChange :: [Int] -> Int -> Int
minimumChange coins amount =
    minimumChange' (reverse $ sort coins) amount

    where
        minimumChange' :: [Int] -> Int -> Int
        minimumChange' [] _                  = 0
        minimumChange' _ 0                   = 0
        minimumChange' (coin : coins) amount =
            (div amount coin)
                + minimumChange' coins (mod amount coin)