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.
In Section
Tutorials