Refactor, simpler and faster.
Solved 1 with Haskell.