function hanoi(n, start, end_, extra, move_disk) if n == 1 then move_disk(1, start, end_) else hanoi(n - 1, start, extra, end_, move_disk) move_disk(n, start, end_) hanoi(n - 1, extra, end_, start, move_disk) end end function print_instruction(disk, start, end_) print("Move disk #"..disk.." from "..start.." to "..end_) end hanoi(3, "a", "c", "b", print_instruction)