Solve problem 22 in Erlang.