diff --git a/haskell/04-hanoi/hanoi.hs b/haskell/04-hanoi/hanoi.hs index 5f64857..6881715 100644 --- a/haskell/04-hanoi/hanoi.hs +++ b/haskell/04-hanoi/hanoi.hs @@ -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])]