forked from steger/pr3-sose2026
Implemented the hanoi exercise
parent
d08714a7a9
commit
ad48ab3983
|
|
@ -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])]
|
||||
|
|
|
|||
Loading…
Reference in New Issue