Problem 8 in c#, Problem 1 in Haskell