Towers of Hanoi: Difference between revisions

no edit summary
m (Slight change to clarify blurb.)
No edit summary
Line 6,308:
14: Move disc from A to C
15: Move disc from B to C</pre>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "hanoi" )
@( description, "Solve the Towers of Hanoi problem with recursion." )
@( see_also, "https://rosettacode.org/wiki/Towers_of_Hanoi" )
@( author, "Ken O. Burtch" );
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure hanoi is
type pegs is (left, center, right);
 
-- Determine the moves
 
procedure solve( num_disks : natural; start_peg : pegs; end_peg : pegs; via_peg : pegs ) is
begin
if num_disks > 0 then
solve( num_disks - 1, start_peg, via_peg, end_peg );
put( "Move disk" )@( num_disks )@( " from " )@( start_peg )@( " to " )@( end_peg );
new_line;
solve( num_disks - 1, via_peg, end_peg, start_peg );
end if;
end solve;
 
begin
-- solve with 4 disks at the left
--solve( 4, left, right, center );
solve( 4, left, right, center );
put_line( "Towers of Hanoi puzzle completed" );
end hanoi;</syntaxhighlight>
 
=={{header|Standard ML}}==
76

edits