-
-
Save built/42971 to your computer and use it in GitHub Desktop.
Didn't like that I had to reassemble the Coins list. Took advantage of parametric temp variables (See Coins variable)
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]=Coins) -> | |
find_variations(Amount, Rest) + find_variations( (Amount - Coin), Coins). | |
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