Skip to content

Instantly share code, notes, and snippets.

# Towers of Hanoi
#
# Write a Towers of Hanoi game:
# http://en.wikipedia.org/wiki/Towers_of_hanoi
#
# In a class `TowersOfHanoi`, keep a `towers` instance variable that is an array
# of three arrays. Each subarray should represent a tower. Each tower should
# store integers representing the size of its discs. Expose this instance
# variable with an `attr_reader`.
#
class TowersOfHanoi
attr_reader :towers
def initialize(towers = [[3,2,1],[],[]])
@towers = towers
end
def move(from_tower, to_tower)
@towers[to_tower] << @towers[from_tower].pop
end