Problem 2 solved in Haskell.
Problem 2 solved in Python.