Skip to content

Instantly share code, notes, and snippets.

Created January 3, 2009 23:07
Show Gist options
  • Save anonymous/42949 to your computer and use it in GitHub Desktop.
Save anonymous/42949 to your computer and use it in GitHub Desktop.
-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