burjui

Money exchange solver in Haskell - very slow naive version

Oct 10th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. countExchanges :: (Integral a) => a -> [a] -> a
  2. countExchanges sum coins
  3.     | sum == 0 = 1
  4.     | sum < 0 || null coins = 0
  5.     | otherwise = countExchanges (sum - head coins) coins +
  6.                   countExchanges sum (tail coins)
  7.  
  8. main = print (countExchanges 100 [50, 25, 10, 5, 1])
Add Comment
Please, Sign In to add comment