<?xml version="1.0" encoding="windows-1252"?>
<node id="263640" title="Hanoi" created="2003-06-06 06:57:11" updated="2005-08-02 10:53:40">
<type id="1588">
obfuscated</type>
<author id="252827">
teamster_jr</author>
<data>
<field name="doctext">
I know there have been discussions about this before (did a search for hanoi) and there is a shorter golf solution out there somewhere, but here's my effort anyway - it is parameterised so you can do hanoi.pl &amp;lt;number of rings&amp;gt;&lt;p&gt;
enjoy!&lt;br&gt;

&lt;code&gt;
sub d{print"\ec";select$q,$q,$q,0.3;for$p(0..2){printf"\e[%d;%dH%s".$/x$
d,$d-$_+2,2*$d*(1+$p)-($$p[$_]?(length$$p[$_])/2:1),$$p[$_]||"|"for 0..$
d-1}}push@0,"-"x(1-2*$_)for-($d=shift||3)+1..0;sub h{my($n,$s,$d,$i)=@_;
if($n&gt;0){h($n-1,$s,$i,$d);push@$d,pop@$s;d;h($n-1,$i,$d,$s)}}h($d,0,2,1)
&lt;/code&gt;
&lt;p&gt;
alex&lt;br&gt;
&lt;small&gt;Edit: Oh sorry guys i so should have said it requires VT100 &lt;/small&gt;&lt;br&gt;
Edit again: I've knocked up &lt;a href=http://www.perlmonks.org/index.pl?node_id=267492&gt;this&lt;/a&gt; non VT100 version for those that can't see the previous one.&lt;br&gt;
HTH</field>
</data>
</node>
