Do problem 4 in Erlang.