Introduction to Haskell (UPenn CIS194)

This is the Homework problem from UPenn CIS194 Introduction to Haskell (Spring 2013) .

Homework 01

UPenn CIS 194 Spring 2013

Homework 1

The problem statement is here. The interesting problem is the classic Tower of Hanoi puzzle. Using Haskell, this problem was reduce to very compact representation of the recursive logic itself:

type Peg = String
type Move = (Peg, Peg)
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
hanoi 0 _ _ _ = []
hanoi 1 x y z = (x, y):[]
hanoi n x y z = (hanoi (n-1) x z y) ++ (hanoi 1 x y z) ++ (hanoi (n-1) z y x)

So elegant and simple once I get my head around the types and how to build up a list.