lib/hanoi/jane/constrained_towers.rb in hanoi-jane-0.1.1 vs lib/hanoi/jane/constrained_towers.rb in hanoi-jane-0.1.2

- old
+ new

@@ -2,46 +2,35 @@ module Jane class ConstrainedTowers < Towers def initialize discs super @base = 3 - - @directions = {} - @stacks[0].each do |disc| - @directions[disc] = :right - end end def ternary rebased end def inspect i = super - - i.delete :binary - i[:ternary] = rebased - + i[:ternary] = i.delete :binary i end private def find_stack - case @source - when 0 - @directions[@disc] = :right - return 1 - when 2 - @directions[@disc] = :left - return 1 - when 1 - if @directions[@disc] == :right + # if we're in the middle + if @source == 1 + # we always move to the right on an even total + if @total % 2 == 0 return 2 else return 0 end end + # otherwise we're at the edges and can only move to the middle + 1 end end end end