Solved #15 in haskell, but is way too slow.