Completed exercise 67, is a more difficult version of problem 18
but same solution works.