Class: Scrambler::Clock

Inherits:
Object
  • Object
show all
Defined in:
lib/scrambler/clock.rb

Instance Method Summary collapse

Instance Method Details

#scramble(length = 0) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/scrambler/clock.rb', line 3

def scramble(length = 0)
  pins = %w(U d)
  states = %w(UUdd dUdU ddUU UdUd dUUU UdUU UUUd UUdU UUUU dddd)
  scramble = states.map do |state|
    moves = []
    u = rand(12) - 5
    d = rand(12) - 5
    moves << 'u=' + u.to_s if state.gsub('d', '').length > 1
    moves << 'd=' + d.to_s if state.gsub('U', '').length > 1
    state + ' ' + moves.join('; ')
  end
  scramble << Array.new(4).map do
    pins.sample
  end.join
  scramble.join(' / ')
end