概要
lazeを見つけたので、やってみた。
再帰、やってみた。
サンプルコード
function: hanoi(int: n, int: a, int: b, int: c) => () {
if (n > 0)
{
hanoi(n - 1, a, c, b);
string: s = "";
s += n;
s += " = ";
s += a;
s += " -> ";
s += c;
print(s);
hanoi(n - 1, c, b, a);
}
}
function: main() => () {
hanoi(3, 0, 2, 1);
}
実行結果
1 = 0 -> 1
2 = 0 -> 2
1 = 2 -> 0
3 = 0 -> 1
1 = 1 -> 2
2 = 1 -> 0
1 = 0 -> 1
以上。