Problems 15 and 16 in Haskell