Skip to content

Commit

Permalink
Remove pointless complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 3, 2018
1 parent 3bc13e5 commit 5cfd293
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 42 deletions.
1 change: 0 additions & 1 deletion lib/hanoi/jane.rb
Expand Up @@ -9,7 +9,6 @@
require 'hanoi/jane/config'
require 'hanoi/jane/exceptions'

require 'hanoi/jane/towers/stack_finders'
require 'hanoi/jane/towers/regular_towers'
require 'hanoi/jane/towers/constrained_towers'
require 'hanoi/jane/towers/animated_towers'
Expand Down
16 changes: 14 additions & 2 deletions lib/hanoi/jane/towers/constrained_towers.rb
@@ -1,8 +1,6 @@
module Hanoi
module Jane
class ConstrainedTowers < RegularTowers
extend ConstrainedStackFinder

def initialize discs = 3
super
@base = 3
Expand All @@ -17,6 +15,20 @@ def inspect
i[:ternary] = i.delete :binary
i
end

def ConstrainedTowers.find_stack stacks:, from:, disc: nil, total:
# if we're in the middle
if from == 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
17 changes: 15 additions & 2 deletions lib/hanoi/jane/towers/regular_towers.rb
Expand Up @@ -3,8 +3,6 @@ module Jane
class RegularTowers
include Enumerable

extend StackFinder

attr_reader :total, :base, :disc, :from, :to, :discs
attr_accessor :stacks

Expand Down Expand Up @@ -88,6 +86,21 @@ def rebased
self.class.rebase @total, @base, @discs
end

def RegularTowers.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
(from + 1) % 3
end

def RegularTowers.starter_stacks discs
[(0...discs).to_a.reverse, [], []]
end
Expand Down
36 changes: 0 additions & 36 deletions lib/hanoi/jane/towers/stack_finders.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/hanoi/jane/version.rb
@@ -1,5 +1,5 @@
module Hanoi
module Jane
VERSION = '0.3.2'
VERSION = '0.3.3'
end
end

0 comments on commit 5cfd293

Please sign in to comment.