Solves problem 14 in haskell