Last active
August 29, 2015 14:22
-
-
Save alcol80/2c3313f5be436d0ea609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Given an infinite number of quarters (25 cents), dimes (10 cents), | |
-- nickels (5 cents) and pennies (1 cent), write code to calculate the | |
-- number of ways of representing n cents. | |
module Coins where | |
comb cents = [(q, d, n, p) | q <- rng 25 cents, | |
d <- rng 10 (cents - 25*q), | |
n <- rng 5 (cents - 25*q - 10*d), | |
p <- rng 1 (cents - 25*q - 10*d - 5*n), | |
25*q + 10*d + 5*n + p == cents] | |
where rng k max = [0..(max `div` k)] | |
result = length . comb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment