Skip to content

Instantly share code, notes, and snippets.

@built
Forked from anonymous/gist:42949
Created January 4, 2009 01:07
Show Gist options
  • Save built/42971 to your computer and use it in GitHub Desktop.
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)
-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