Do problem 23 in Erlang. Needs some speeding up...