in reply to Recursion: The Towers of Hanoi problem
My own code, for a class I had
==
Kwyjibo. A big, dumb, balding North American ape. With no chin.
Number of discs is supplied as $ARGV[0] so, yeah. You could continue to play with this to see how much more it will compress. (I really didn't like the TA's for this class and eventually started using map and grep in all the programs.)#!/usr/bin/perl -w use strict; han('A','B','C',$ARGV[0]); sub han{ return if $_[3] <= 0; han($_[0],$_[2],$_[1],$_[3]-1); print "Move disc $_[3] from $_[0] to $_[2]\n"; han($_[1],$_[0],$_[2],$_[3]-1); }
Edit:
made it shorter.
==
Kwyjibo. A big, dumb, balding North American ape. With no chin.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Recursion: the Towers of Hanoi problem
by Jasper (Chaplain) on Oct 21, 2004 at 14:02 UTC | |
by abitkin (Monk) on Oct 21, 2004 at 16:20 UTC | |
by Jasper (Chaplain) on Oct 21, 2004 at 18:15 UTC | |
by abitkin (Monk) on Oct 25, 2004 at 14:38 UTC | |
Re^2: Recursion: the Towers of Hanoi problem
by SpanishInquisition (Pilgrim) on Oct 20, 2004 at 17:47 UTC |
In Section
Tutorials