Ruby
The Towers of Hanoi using the Ruby programming language.
#! /usr/bin/ruby
#
# The Towers Of Hanoi
# Ruby
# Copyright (C) 1998 Amit Singh. All Rights Reserved.
# http://hanoi.kernelthread.com
#
def hanoi(n, f, t, u)
if (n <= 1)
move = "move " + f + " --> " + t + "\n"
print move
else
hanoi(n - 1, f, u, t)
hanoi(1, f, t, u)
hanoi(n - 1, u, t, f)
end
end
if (ARGV.size != 1)
STDERR.print "usage: hanoi.rb <n>\n"
exit 1
end
hanoi(ARGV[0].to_i, "1", "3", "2");