Created
January 3, 2009 23:07
-
-
Save anonymous/42949 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-module(change2). | |
-export([find_variations/2]). | |
-export([count_change/1]). | |
find_variations(0, _) -> 1; % No amount given. | |
find_variations(_, []) -> 0; % No coins given. | |
find_variations(Amount, _) % Amount is impossible. | |
when Amount < 0 -> 0; | |
find_variations(Amount, [Coin|Rest]) -> | |
find_variations(Amount, Rest) + find_variations( (Amount - Coin), [Coin] ++ Rest). | |
count_change(Amount) -> | |
find_variations(Amount, [50, 25, 10, 5, 1]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment