Ruby_ tower of Hanoi

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

test in mac:

save as hanoi.rb;then run:

#ruby hanoi.rb 4

#! /usr/bin/ruby
def hanoi(floor, towerA, towerB, towerC)
  if floor == 0
    print "get ", towerA, " to ", towerC, "\n"
    hanoi(floor - 1, towerA, towerC, towerB)
    print "get ", towerA, " to ", towerC, "\n"
    hanoi(floor - 1, towerB, towerA, towerC)

hanoi(Integer(ARGV[0]), 'A', 'B', 'C')

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Andrew at January 21, 2014 - 5:33 AM