Implementation of problem 23 in Haskell. Kind of slow though. Emulates a for loop using recursion.