Class: Scrambler::Pyraminx

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

Instance Method Summary collapse

Instance Method Details

#scramble(length = 25) ⇒ Object



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

def scramble(length = 25)
  turns = %w(U L R B)
  variants = ['', "'"]

  tip_turns = turns.map &:downcase
  tip_length = rand(3) + 1
  scramble = (1..tip_length).map do
    tip_turns.delete(tip_turns.sample) + variants.sample
  end

  axis = rand turns.size
  scramble += ((tip_length + 1)..length).map do
    axis = (axis + rand(turns.size - 1) + 1) % turns.size
    turns[axis] + variants.sample
  end

  scramble.join(" ")
end