1
我正在嘗試實施河內塔的遞歸函數。哈希克爾實施河內塔時出錯
的算法是:
Move n−1 disks from peg AA to peg C using peg B as intermediate storage.
Move the nth disk from peg A to peg B,
Move n−1 disks from peg C to peg BB using peg A as intermediate storage.
Eample:
hanoi 2 "a" "b" "c" =
[("a","c"), ("a","b"), ("c","b")]
這是我實現
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
hanoi x "a" "b" "c"
| x <= 0 = []
| x == 1 = [("a", "b")]
| otherwise = (hanoi (x-1) "a" "c" "b") ++ [("a", "b")] ++ (hanoi (x-1) "c" "b" "a")
但是我得到一個錯誤說:there is un-exhausted pattern
。 這是什麼意思我該如何解決它?
參數不需要用引號引起來。在這裏,他們甚至不應該。 –