Skip to content

Instantly share code, notes, and snippets.

@patrickgombert
Last active December 12, 2015 01:58
Show Gist options
  • Save patrickgombert/4694802 to your computer and use it in GitHub Desktop.
Save patrickgombert/4694802 to your computer and use it in GitHub Desktop.
erlang coin changer with absolute priority premise scoring
change(Amount) -> % => Binding 2 x 1
{Coins, _} = lists:foldl(fun(Denom, {Coins, Total}) -> % => Invocation 2 x 1, Binding 4 x 1, Constant 1 x 1
Floor = floor(Total / Denom), % => Binding 1 x 1, Invocation 2 x 2
{Coins ++ lists:duplicate(Floor, Denom), Total - (Floor * Denom)} % => Invocation 2 x 4
end, {[], Amount}, [25, 10, 5, 1]), % => Constant 2 x 1
Coins.
% Total = 2 + 2 + 4 + 1 + 1 + 4 + 8 + 2 = 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment