Module: Hanoi::Jane::StackFinder
- Included in:
- Towers
- Defined in:
- lib/hanoi/jane/towers/stack_finders.rb
Instance Method Summary collapse
Instance Method Details
#find_stack(stacks:, from:, disc:, total: nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hanoi/jane/towers/stack_finders.rb', line 4 def find_stack stacks:, from:, disc:, total: nil # if the next stack is empty, move there if stacks[(from + 1) % 3] == [] return (from + 1) % 3 end # if the next stack has a smaller top disc than our disc, go one more over if stacks[(from + 1) % 3][-1] < disc return (from + 2) % 3 end # default to the next one return (from + 1) % 3 end |