Towers of Hanoi: Difference between revisions

+Stata
(+Stata)
Line 3,762:
fun hanoi(0, a, b, c) = [] |
hanoi(n, a, b, c) = hanoi(n-1, a, c, b) @ [(a,b)] @ hanoi(n-1, c, b, a);
 
=={{header|Stata}}==
 
<lang stata>function hanoi(n, a, b, c) {
if (n>0) {
hanoi(n-1, a, c, b)
printf("Move from %f to %f\n", a, b)
hanoi(n-1, c, b, a)
}
}
 
hanoi(3, 1, 2, 3)
 
Move from 1 to 2
Move from 1 to 3
Move from 2 to 3
Move from 1 to 2
Move from 3 to 1
Move from 3 to 2
Move from 1 to 2</lang>
 
=={{header|Swift}}==
1,336

edits