class ScatterSwap::Swapper
Constants
- DIGITS
Public Class Methods
instance(spin)
click to toggle source
# File lib/scatter_swap/swapper.rb, line 9 def instance(spin) @all_swapper_maps[spin] ||= new(spin) end
new(spin)
click to toggle source
# File lib/scatter_swap/swapper.rb, line 16 def initialize(spin) @spin = spin @caches = {} end
Public Instance Methods
generate(index)
click to toggle source
# File lib/scatter_swap/swapper.rb, line 21 def generate(index) @caches[index] ||= generate_without_cache(index) end
Private Instance Methods
generate_without_cache(index)
click to toggle source
# File lib/scatter_swap/swapper.rb, line 27 def generate_without_cache(index) array = DIGITS.dup sum = 0 10.times.map.with_index do |i| sum = (sum + ((index + i) ^ @spin) - 1) % (10 - i) next array.delete_at(sum) end end