Towers of Hanoi: Difference between revisions

→‎{{header|Imp77}}: added tested output
(Added Uiua solution)
(→‎{{header|Imp77}}: added tested output)
(5 intermediate revisions by 4 users not shown)
Line 10:
{{trans|Python}}
 
<syntaxhighlight lang="11l">F hanoi(ndisks, startPeg = 1, endPeg = 3) -> NVoid
I ndisks
hanoi(ndisks - 1, startPeg, 6 - startPeg - endPeg)
Line 1,567:
<
]</syntaxhighlight>
 
=={{header|Bruijn}}==
{{trans|Python}}
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/Number .
:import std/String .
 
hanoi y [[[[=?2 empty go]]]]
go [(4 --3 2 0) ++ str ++ (4 --3 0 1)] ((+6) - 1 - 0)
str "Move " ++ disk ++ " from " ++ source ++ " to " ++ destination ++ "\n"
disk number→string 3
source number→string 2
destination number→string 1
</syntaxhighlight>
 
=={{header|C}}==
Line 3,393 ⟶ 3,408:
return
end</syntaxhighlight>
 
=={{header|Imp77}}==
<syntaxhighlight lang="Imp77">
%begin
%routine do hanoi(%integer n, f, t, u)
do hanoi(n - 1, f, u, t) %if n >= 2
print string("Move disk from ".itos(f,0)." to ".itos(t,0).to string(nl))
do hanoi(n - 1, u, t, f) %if n >= 2
%end
do hanoi(4, 1, 2, 3)
print string("Towers of Hanoi puzzle completed!".to string(nl))
%end %of %program
</syntaxhighlight>
{{out}}
<pre>
Move disk from 1 to 3
Move disk from 1 to 2
Move disk from 3 to 2
Move disk from 1 to 3
Move disk from 2 to 1
Move disk from 2 to 3
Move disk from 1 to 3
Move disk from 1 to 2
Move disk from 3 to 2
Move disk from 3 to 1
Move disk from 2 to 1
Move disk from 3 to 2
Move disk from 1 to 3
Move disk from 1 to 2
Move disk from 3 to 2
Towers of Hanoi puzzle completed!
</pre>
 
=={{header|Inform 7}}==
Line 3,564 ⟶ 3,611:
const go = hanoi(n - 1);
 
return Boolean(n) ? [
...go(a,? c, b),[
...[go(a, c, b),
[a, b],
] ...go(c, b, a)
...go(c, b, a)]
] : [];
};
 
Line 3,576 ⟶ 3,623:
// ---------------------- TEST -----------------------
return hanoi(3)("left", "right", "mid")
.map(d => `${d[0]} -> ${d[1]}`)
.join("\n");
})();</syntaxhighlight>
{{Out}}
3

edits