Skip to content

Instantly share code, notes, and snippets.

@wancw
Created June 16, 2009 20:07
Show Gist options
  • Save wancw/130861 to your computer and use it in GitHub Desktop.
Save wancw/130861 to your computer and use it in GitHub Desktop.
--
-- Haskell 版本的分錢程式
--
divideInto :: (Integral a) => a -> a -> [a]
divideInto total n = divideAux total n []
where
divideAux total n xs
| n > 0 = divideAux (total-first) (n-1) (first:xs)
| otherwise = xs
where
first = round ( (toRational total) / (toRational n) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment