1
0
Fork 0

Implemented the hanoi exercise

main
Oliver Stolle 2026-06-01 20:05:36 +00:00
parent d08714a7a9
commit ad48ab3983
1 changed files with 6 additions and 2 deletions

View File

@ -10,8 +10,12 @@ move n src dst = "move disk " ++ show n ++ " from " ++ [src] ++ " to " ++ [dst]
-- transfers a number of disks (the Int) from a source (the first Char) rod to a destination (the second Char) rod via a temp (the third char) rod
-- returns a list of required operations
hanoi :: (Int,Char,Char,Char) -> [String]
--TODO: implement here
hanoi (n, src, dst, tmp)
| n <= 0 = []
| n == 1 = [move 1 src dst]
| otherwise = hanoi (n - 1, src, tmp, dst)
++ [move n src dst]
++ hanoi (n - 1, tmp, dst, src)
-- Source, Destination, Temp
hanoiTests :: [((Int, Char, Char, Char), [String])]