Problem 1 solutiosn in C#, F#, Prolog, and Haskell