Problem 2 in Python and Haskell.