Sha256: 76c54992c5861bf846dab79b510d4cea0578d43ca4db18452fd6fdf079b9ff67
Contents?: true
Size: 474 Bytes
Versions: 2
Compression:
Stored size: 474 Bytes
Contents
require_relative "./ring" module HanoiTower class Tower def initialize(ring_size) @rings = ring_size.times.reverse_each.map {|v| Ring.new(v + 1) } end def can_push?(ring) if @rings.last.nil? true else @rings.last.can_push?(ring) end end def push ring @rings << ring end def pop @rings.pop end def to_s @rings.map(&:to_s).join('-') end attr_reader :rings end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hanoi_tower-0.1.1 | lib/hanoi_tower/tower.rb |
hanoi_tower-0.1.0 | lib/hanoi_tower/tower.rb |