~ubuntu-branches/ubuntu/warty/bash/warty

« back to all changes in this revision

Viewing changes to examples/scripts/hanoi.bash

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2002-04-08 20:51:41 UTC
  • Revision ID: james.westby@ubuntu.com-20020408205141-qovkhu3a90201hf2
Tags: upstream-2.05a
ImportĀ upstreamĀ versionĀ 2.05a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Towers of Hanoi in bash
 
2
#
 
3
# cribbed from the ksh93 book, example from exercises on page 85
 
4
#
 
5
# Chet Ramey
 
6
# chet@po.cwru.edu
 
7
 
 
8
hanoi() # n from to spare
 
9
{
 
10
    typeset -i nm1=$1-1
 
11
    ((nm1>0)) && hanoi $nm1 $2 $4 $3
 
12
    echo "Move disc $2 to $3"
 
13
    ((nm1>0)) && hanoi $nm1 $4 $3 $2
 
14
}
 
15
 
 
16
case $1 in
 
17
[1-9])
 
18
      hanoi $1 1 2 3;;
 
19
*)    echo "${0##*/}: Argument must be from 1 to 9"
 
20
      exit 1;;
 
21
esac