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 <number of rings>
enjoy!
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>0){h($n-1,$s,$i,$d);push@$d,pop@$s;d;h($n-1,$i,$d,$s)}}h($d,0,2, +1)
alex
Edit: Oh sorry guys i so should have said it requires VT100
Edit again: I've knocked up this non VT100 version for those that can't see the previous one.
HTH
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Hanoi
by dorko (Prior) on Jun 06, 2003 at 15:21 UTC | |
Re: Hanoi
by one4k4 (Hermit) on Jun 06, 2003 at 18:40 UTC | |
by educated_foo (Vicar) on Jun 06, 2003 at 18:59 UTC | |
by one4k4 (Hermit) on Jun 06, 2003 at 20:18 UTC | |
by daeve (Deacon) on Jun 07, 2003 at 20:18 UTC | |
by denthijs (Acolyte) on Jun 08, 2003 at 11:12 UTC | |
by daeve (Deacon) on Jun 08, 2003 at 16:21 UTC | |
by teamster_jr (Curate) on Jun 16, 2003 at 11:19 UTC | |
| |
Re: Hanoi
by teamster_jr (Curate) on Jun 20, 2003 at 09:00 UTC |
Back to
Obfuscated Code