Solve problem 21 using Erlang.