This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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`. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |