0

I'm trying to code something that gives me the orientation of the sides of a Rubik's cube after rotating it.

It's about the rotation of one side of a Rubik's cube. When solved (looking at the white side) all the 4 corners which would be moved by this rotation have a specific orientation.

I defined it like that:

E1 = (W,o,b)
E2 = (W,b,r)
E3 = (W,r,g)
E4 = (W,g,o)

This represents the orientation of each corners. First variable is the side to which the white side is facing. (solved cube, so all whites are looking at white) second is the orientation the color left of white is facing, and last one is the side the last color is facing. I can also write -r instead of o and -b instead of g, I think that makes it easier.

So when I turn it clockwise, the last two arguments would rotate to show the new orientation. For the first corner it would be from (W,-r,b) going to (W,b,r), that's the orientation of the second corner right now.

So what I need is a method to show me the new orientation of the corner. It should rotate the values from ( -r -> b -> r -> -b ) and back to the beginning.

I thought a list would be nice, but I don't know if its the best way since I don't know how to jump back to the beginning after increasing the index to the max.

For me it reminds me about the derivative of sin and cos : sin(x) -> cosx -> -sinx -> -cosx maybe I can use this somehow to rotate those indices?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Nic0lodeon
  • 77
  • 6
  • maybe I should mention : the letters in brackets represent the side one of the 3 colors of the corner is facing , the letters represent the colors so -r would be orange etc. just find it better to call it this than x,y,z – Nic0lodeon Jun 20 '20 at 13:31

1 Answers1

0

Rotating through a list can be achieved using modulus (%).

values = ['-r', 'b', 'r', '-b']

index = 0
print(values[index % len(values)])

>>> -r


index = 5
print(values[index % len(values)])

>>> b

See Understanding The Modulus Operator % for explanation regarding the modulo operator.

ScootCork
  • 3,411
  • 12
  • 22