#!/usr/bin/env ruby # # Algorithm 1.1 # "Compared to What?" by Gregory J. E. Rawlins # def hanoi n, cur, temp, dest if n == 1 puts "\t#{cur} -> #{dest}" else hanoi(n - 1, cur, dest, temp) puts "\t#{cur} -> #{dest}" hanoi(n - 1, temp, cur, dest) end end n = 5 puts "Moving #{n} discs..." hanoi n, 'A', 'B', 'C'