Coins problem in Erlang How many different ways can 200 be made using any number of coins? The possible denominations are 1, 2, 5, 10, 20, 50, 100, 200.

-module(coins).
-export([coins/2]).


coins(_, 0) -&gt; 1;
coins([], _) -&gt; 0;
coins(_, Goal) when Goal &lt; 0 -&gt; 0;
coins([H|T], Goal) -&gt;
  coins([H|T], Goal-H) + coins(T, Goal).


The call is:

1&gt; c(coins).
2&gt; coins:coins([1, 2, 5, 10, 20, 50, 100, 200], 200).
73682
You can easily give more structure to your code:

-module(coins).
-export([coins/2]).

-spec coins([CoinValue::integer()], Goal::integer()) -&gt; Combinations::integer().

coins(_, 0) -&gt; 1;
coins([], _) -&gt; 0;
coins(_, Goal) when Goal &lt; 0 -&gt; 0;
coins([CoinValue|Rest], Goal) -&gt;
  WithCoinValue = coins([H|T], Goal-H),
  WithoutCoinValue = coins(T, Goal),
  WithCoinValue + WithoutCoinValue.