Towers of Hanoi: Difference between revisions

Content added Content deleted
(added Bracmat)
Line 447: Line 447:
hanoi(3,3,1,2);
hanoi(3,3,1,2);
}</lang>
}</lang>

The same as above, with optional static type annotations and styled according to http://www.dartlang.org/articles/style-guide/
<lang dart>main() {
String say(String from, String to) => "$from ---> $to";

hanoi(num height, num toPole, num fromPole, num usePole) {
if (height > 0) {
hanoi(height - 1, usePole, fromPole, toPole);
print(say(fromPole.toString(), toPole.toString()));
hanoi(height - 1, toPole, usePole, fromPole);
}
}

hanoi(3, 3, 1, 2);
}</lang>

{{out}}
{{out}}
<pre>move 1 ---> 3
<pre>move 1 ---> 3