Towers of Hanoi: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 1,397: Line 1,397:
putStrLn $ "Move " ++ show a ++ " to " ++ show b
putStrLn $ "Move " ++ show a ++ " to " ++ show b
hanoiM' (n - 1) c b a</lang>
hanoiM' (n - 1) c b a</lang>

=={{header|Elena}}==
=={{header|Elena}}==
ELENA 4.x :
ELENA 4.x :
Line 1,578: Line 1,579:
| a, b -> printf "Move disc from %A to %A\n" a b)
| a, b -> printf "Move disc from %A to %A\n" a b)
0</lang>
0</lang>

=={{header|FALSE}}==
<lang false>["Move disk from "$!\" to "$!\"
"]p: { to from }
[n;0>[n;1-n: @\ h;! @\ p;! \@ h;! \@ n;1+n:]?]h: { via to from }
4n:["right"]["middle"]["left"]h;!%%%</lang>


=={{header|Factor}}==
=={{header|Factor}}==
Line 1,607: Line 1,602:
1->3</pre>
1->3</pre>


=={{header|Fōrmulæ}}==
=={{header|FALSE}}==
<lang false>["Move disk from "$!\" to "$!\"

"]p: { to from }
In [http://wiki.formulae.org/Towers_of_Hanoi this] page you can see the solution of this task.
[n;0>[n;1-n: @\ h;! @\ p;! \@ h;! \@ n;1+n:]?]h: { via to from }

4n:["right"]["middle"]["left"]h;!%%%</lang>
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.

The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.


=={{header|Forth}}==
=={{header|Forth}}==
Line 1,776: Line 1,769:
Towers of Hanoi puzzle solved.
Towers of Hanoi puzzle solved.
</pre>
</pre>

=={{header|Fōrmulæ}}==

In [http://wiki.formulae.org/Towers_of_Hanoi this] page you can see the solution of this task.

Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.

The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.


=={{header|GAP}}==
=={{header|GAP}}==
Line 2,630: Line 2,631:


:- end_object.</lang>
:- end_object.</lang>



=={{header|LOLCODE}}==
=={{header|LOLCODE}}==
Line 3,339: Line 3,339:
};
};
};</lang>
};</lang>

=={{header|Perl 6}}==
<lang perl6>subset Peg of Int where 1|2|3;

multi hanoi (0, Peg $a, Peg $b, Peg $c) { }
multi hanoi (Int $n, Peg $a = 1, Peg $b = 2, Peg $c = 3) {
hanoi $n - 1, $a, $c, $b;
say "Move $a to $b.";
hanoi $n - 1, $c, $b, $a;
}</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 3,549: Line 3,539:
(println 'Move 'disk 'from A 'to B)
(println 'Move 'disk 'from A 'to B)
(move (dec N) C B A) ) )</lang>
(move (dec N) C B A) ) )</lang>

=={{header|Pop11}}==
<lang pop11>define hanoi(n, src, dst, via);
if n > 0 then
hanoi(n - 1, src, via, dst);
'Move disk ' >< n >< ' from ' >< src >< ' to ' >< dst >< '.' =>
hanoi(n - 1, via, dst, src);
endif;
enddefine;

hanoi(4, "left", "middle", "right");</lang>


=={{header|PL/I}}==
=={{header|PL/I}}==
Line 3,583: Line 3,562:
end tower;</lang>
end tower;</lang>


=={{Header|PlainTeX}}==
=={{header|PlainTeX}}==


<lang TeX>\newcount\hanoidepth
<lang TeX>\newcount\hanoidepth
Line 3,604: Line 3,583:
\hanoi{5}
\hanoi{5}
\end</lang>
\end</lang>

=={{header|Pop11}}==
<lang pop11>define hanoi(n, src, dst, via);
if n > 0 then
hanoi(n - 1, src, via, dst);
'Move disk ' >< n >< ' from ' >< src >< ' to ' >< dst >< '.' =>
hanoi(n - 1, via, dst, src);
endif;
enddefine;

hanoi(4, "left", "middle", "right");</lang>


=={{header|PostScript}}==
=={{header|PostScript}}==
Line 4,268: Line 4,258:
(hanoi 4 'left 'middle 'right)
(hanoi 4 'left 'middle 'right)
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>subset Peg of Int where 1|2|3;

multi hanoi (0, Peg $a, Peg $b, Peg $c) { }
multi hanoi (Int $n, Peg $a = 1, Peg $b = 2, Peg $c = 3) {
hanoi $n - 1, $a, $c, $b;
say "Move $a to $b.";
hanoi $n - 1, $c, $b, $a;
}</lang>


=={{header|Rascal}}==
=={{header|Rascal}}==
Line 4,887: Line 4,888:
14: Move disc from A to C
14: Move disc from A to C
15: Move disc from B to C</pre>
15: Move disc from B to C</pre>

=={{header|Standard ML}}==
=={{header|Standard ML}}==
fun hanoi(0, a, b, c) = [] |
fun hanoi(0, a, b, c) = [] |
Line 5,107: Line 5,109:
EndIf
EndIf
Return</lang>
Return</lang>

=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
{{works with|bash}}
{{works with|bash}}
Line 5,255: Line 5,258:
Move from left peg to right peg.
Move from left peg to right peg.
</pre>
</pre>

=={{header|XSLT}}==
<lang xml><xsl:template name="hanoi">
<xsl:param name="n"/>
<xsl:param name="from">left</xsl:param>
<xsl:param name="to">middle</xsl:param>
<xsl:param name="via">right</xsl:param>
<xsl:if test="$n &gt; 0">
<xsl:call-template name="hanoi">
<xsl:with-param name="n" select="$n - 1"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$via"/>
<xsl:with-param name="via" select="$to"/>
</xsl:call-template>
<fo:block>
<xsl:text>Move disk from </xsl:text>
<xsl:value-of select="$from"/>
<xsl:text> to </xsl:text>
<xsl:value-of select="$to"/>
</fo:block>
<xsl:call-template name="hanoi">
<xsl:with-param name="n" select="$n - 1"/>
<xsl:with-param name="from" select="$via"/>
<xsl:with-param name="to" select="$to"/>
<xsl:with-param name="via" select="$from"/>
</xsl:call-template>
</xsl:if>
</xsl:template></lang>

<xsl:call-template name="hanoi"><xsl:with-param name="n" select="4"/></xsl:call-template>


=={{header|XQuery}}==
=={{header|XQuery}}==
Line 5,368: Line 5,341:
</move>
</move>
</hanoi></lang>
</hanoi></lang>

=={{header|XSLT}}==
<lang xml><xsl:template name="hanoi">
<xsl:param name="n"/>
<xsl:param name="from">left</xsl:param>
<xsl:param name="to">middle</xsl:param>
<xsl:param name="via">right</xsl:param>
<xsl:if test="$n &gt; 0">
<xsl:call-template name="hanoi">
<xsl:with-param name="n" select="$n - 1"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$via"/>
<xsl:with-param name="via" select="$to"/>
</xsl:call-template>
<fo:block>
<xsl:text>Move disk from </xsl:text>
<xsl:value-of select="$from"/>
<xsl:text> to </xsl:text>
<xsl:value-of select="$to"/>
</fo:block>
<xsl:call-template name="hanoi">
<xsl:with-param name="n" select="$n - 1"/>
<xsl:with-param name="from" select="$via"/>
<xsl:with-param name="to" select="$to"/>
<xsl:with-param name="via" select="$from"/>
</xsl:call-template>
</xsl:if>
</xsl:template></lang>

<xsl:call-template name="hanoi"><xsl:with-param name="n" select="4"/></xsl:call-template>


=={{header|Yabasic}}==
=={{header|Yabasic}}==