Solved 2 with Haskell.