Jump to content

Towers of Hanoi: Difference between revisions

m
m (→‎{{header|AppleScript}}: (normalised argument order of map to map :: (a -> b) -> [a] -> [b] ))
Line 1,714:
}
move(4, "A", "B", "C");</lang>
 
 
Or, as a functional expression, rather than a statement with side effects:
 
<lang JavaScript>(function () {
 
// hanoi :: n -> s -> s -> s -> [[s, s]]
function hanoi(n, a, b, c) {
return n ? hanoi(n - 1, a, c, b).concat(
Line 1,725 ⟶ 1,726:
).concat(hanoi(n - 1, c, b, a)) : [];
}
 
return hanoi(3, 'left', 'right', 'mid').map(function (d) {
.map(function (d) {
return d[0] + ' -> ' + d[1];
});
})();</lang>
 
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.