|
by David M Williams
|
|
Thursday, 05 June 2008 |
|
Page 4 of 5 I entered the command cat Hanoi.sh to view the code and make sure I had saved it completely. My terminal prompt filled with text.
#! /bin/bash
#
# The Towers Of Hanoi
# Bash script
# Copyright (C) 2000 Amit Singh. All Rights Reserved.
# http://hanoi.kernelthread.com
#
# Last tested under bash version 2.05b.0(13)-release
#
dohanoi() {
case $1 in
0)
;;
*)
dohanoi "$(($1-1))" $2 $4 $3
echo move $2 "-->" $3
dohanoi "$(($1-1))" $4 $3 $2
;;
esac
}
case $# in
1)
case $(($1>0)) in
1)
dohanoi $1 1 3 2
exit 0;
;;
*)
echo "$0: illegal value for number of disks";
exit 2;
;;
esac
;;
*)
echo "usage: $0 N"
exit 1;
;;
esac
It all appeared to be in order. I executed ./Hanoi.sh to invoke the script; its usage instruction displayed reminding me I had to pass a command-line parameter of the number of discs I had to work with. What was it again? 10?
./Hanoi.sh 10
My screen flooded with text as the script showed how to solve the puzzle, move after move after move. Finally it came to a halt, with move number 1,023 sitting at the conclusion. That was it, the optimal number of moves for a 10-piece tower of Hanoi puzzle was 1,023.
“1023,” I said. “The code is 1023.”
The assembled animals gasped. It could not be so. Were they going to have their hopes dashed again by numerical error? Or indeed, perhaps the legend was precisely that – a legend without substance?
I tapped in the four digit code 1 – 0 – 2 – 3 and waited. Nothing happened. I could see the disappointment in those around me, and felt my own disappointment as I realised I would soon be shovelling rock with my bare hand.
“Try pressing hash,” squeaked a voice from the back. It was an animal I had not noticed before, some type of nutty squirrel. I tapped the hash key and almost before I had even lifted my hand back off there was a beep and a click and then a puff of dust as something moved in front of us.
“A door! A door!” the surrounding flock chanted. Sure enough, a door had appeared. The story was true. There was another entrance, and it had been hidden all this time. I tried to open it but it was jammed through years of disuse. Fortunately, the crowd around me had the strength of beasts of burden and pulled it open with nary a grunt or sweat.
A corridor sat before us. And yet, it was not a dark corridor. There were rectangles of light dotting the path. I looked in and up and realised the roof was made of mesh-like tiles. My goodness, I realised, it was a removable floor cavity. Something I had not seen for many years.
You may think, precious reader, we’re nearly at the point of success. But this turned to near horror. Please read on for the shocking conclusion.
CONTINUED
|