summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdoardo La Greca2025-04-01 18:03:09 +0200
committerEdoardo La Greca2025-04-01 18:03:09 +0200
commit90dc9e1e36cddadee9f93141b29cc26e6c49885e (patch)
treed368a561e09eac6f9f9f828df20a77297e955354
parent5c0cc518bbc165153c48bb87b9e776760028973a (diff)
add exercise 5 to first lecture's homeworkHEADmaster
-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