Sha256: 5853d82f40ea79cd80c7ea72261519f1fbf34cba7b7f84f23e633b815bb00035

Contents?: true

Size: 770 Bytes

Versions: 1

Compression:

Stored size: 770 Bytes

Contents

module Hanoi
  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
      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
            return 2
          else
            return 0
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanoi-jane-0.1.1 lib/hanoi/jane/constrained_towers.rb