Lesson goal: Introduction to the 3D Rubik's Cube

Previous: Musical Symmetries: Bach's Geometry & Transformations | Home | Next: Make a 3D-printable XY-graph

Invented in 1974 by Hungarian architect Ernő Rubik, the Rubik's Cube is the world's most famous mechanical puzzle and a cornerstone of 3D transformation geometry and mathematical Group Theory.

The Anatomy and Sections of the 3x3x3 Cube

Although the cube appears to be a single solid object, it actually consists of 26 separate movable pieces (called "cubies") anchored around a hidden central 3D spider mechanism:
  • 6 Center Pieces: Located at the center of each face. Each center piece has only 1 colored sticker. Centers cannot change their position relative to each other; they define the home color of each face (White opposite Yellow, Green opposite Blue, Red opposite Orange).
  • 12 Edge Pieces: Located between corners along each edge. Each edge piece has 2 colored stickers.
  • 8 Corner Pieces: Located at the 8 vertices of the cube. Each corner piece has 3 colored stickers.


The 6 Faces and Singmaster Move Notation

To command moves on the cube, mathematicians and cubers use Singmaster notation, named after mathematician David Singmaster. Each letter represents a 90° clockwise turn of one face:
  • U (Up / Top face)  |  D (Down / Bottom face)
  • L (Left face)  |  R (Right face)
  • F (Front face)  |  B (Back face)
  • Prime ('): A turn with an apostrophe means a 90° counter-clockwise turn (e.g., R' is Right counter-clockwise).
  • Double turn (2): A 180° half-turn (e.g., U2, R2).


Controlling the 3D Cube with Code

With CodeByMath's interactive 3D cube engine, you can control the cube using simple commands:
  • cube() initializes and displays the interactive 3D cube in the visualization window.
  • cube_move("R U R' U'") executes one or more face turns in sequence with smooth 3D animation.
  • cube_spin("y") or cube_spin("x") spins the entire cube in 3D to view different faces.
  • cube_reset() resets the cube back to its solved state.
  • cube_scramble(15) applies a sequence of random moves to scramble the cube.
cube()
cube_move("R U R' U'")

cube_move("????")
Move the mouse over a dotted box for more information.

  • Interactive 3D Orbiting: Click and drag with your mouse directly on the cube in the visualization window to spin and inspect all 6 faces from any perspective!
  • Interactive Toolbar: Use the Reset, Scramble, Spin (y), and Spin (x) buttons on the cube card header to experiment dynamically.
  • Mathematical Cycle Order: In Group Theory, repeating any fixed sequence of moves on a finite permutation group will eventually return the object to its starting state. Repeating R U R' U' exactly 6 times returns the cube to solved!

Now you try. In Group Theory, repeating the 4-move sequence (R U R' U') six times returns the entire cube back to its solved state! Try putting cube_move("R U R' U'") inside a for-loop: for i = 1, 6 do cube_move("R U R' U'") end. Does it return to solved?

Type your code here:


See your results here: