# 漢諾塔 a = "A" b = "B" c = "C" def hano(a, b, c, n): if n == 1: print("{} --> {}".format(a, c)) if n == 2: print("{} --> {}".format(a, c)) print("{} --... ...
# 漢諾塔 a = "A" b = "B" c = "C" def hano(a, b, c, n): if n == 1: print("{} --> {}".format(a, c)) if n == 2: print("{} --> {}".format(a, c)) print("{} --> {}".format(a, b)) print("{} --> {}".format(b, c)) return None hano(a, b, c, n - 1) print("{} --> {}".format(a, c)) hano(b, a, c, n - 1) hano(a, b, c, 5)
A --> C A --> B B --> C A --> C B --> C B --> A A --> C A --> C B --> C B --> A A --> C B --> C A --> C A --> B B --> C A --> C B --> C B --> A A --> C B --> C A --> C A --> B B --> C B --> C A --> C A --> B B --> C A --> C B --> C B --> A A --> C