Jump to content

Towers of Hanoi: Difference between revisions

PascalABC.NET
(→‎{{header|Imp77}}: added tested output)
(PascalABC.NET)
Line 4,946:
MoveStack(4,tpLeft,tpCenter,tpRight);
end.</syntaxhighlight>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
## procedure Hanoi(n,rfrom,rto,rwork: integer);
begin
if n = 0 then
exit;
Hanoi(n-1,rfrom,rwork,rto);
Print($'{rfrom}→{rto} ');
Hanoi(n-1,rwork,rto,rfrom);
end;
Hanoi(5,1,3,2);
</syntaxhighlight>
{{out}}
<pre>
1→3 1→2 3→2 1→3 2→1 2→3 1→3 1→2 3→2 3→1 2→1 3→2 1→3 1→2 3→2 1→3 2→1 2→3 1→3 2→1 3→2 3→1 2→1 2→3 1→3 1→2 3→2 1→3 2→1 2→3 1→3 </pre>
 
=={{header|Perl}}==
170

edits

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