summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lec01/hw.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/lec01/hw.hs b/lec01/hw.hs
index 8f4197d..19dd24f 100644
--- a/lec01/hw.hs
+++ b/lec01/hw.hs
@@ -40,3 +40,14 @@ sumDigits (x:xs)
validate :: Integer -> Bool
validate n = sumDigits (doubleEveryOther (toDigits n)) `mod` 10 == 0
+
+
+-- exercise 5
+
+type Peg = String
+type Move = (Peg, Peg)
+hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
+hanoi 0 _ _ _ = []
+hanoi 1 a b c = [(a,c)]
+hanoi 2 a b c = [(a,b), (a,c), (b,c)]
+hanoi n a b c = hanoi (n-1) a c b ++ [(a,c)] ++ hanoi (n-1) b a c