Rubik's Cube in Prolog – Order

Prolog tackles the Rubik’s Cube—fans bicker over what really matters

TLDR: A coder used Prolog to model a 2×2 Rubik’s Cube and showed a face turn has order 4—four twists reset it. Comments erupted over whether you need positions or just orientations, with a side of Play Store cease-and-desist drama, making math and puzzles weirdly spicy.

Kenichi Sasagawa modeled a tiny 2×2 Rubik’s Cube in Prolog (a logic-based coding language) and showed that turning the front face four times puts the cube back to normal. That math fact is called “order,” and the post walks through it simply. But the real twist? The comments went off.

One bold claim stole the spotlight: “you only need orientations, not positions” to describe a cube, argued one commenter, sparking a mini turf war between the orientation-only camp and the “it’s a permutation of numbers” crew. Another reader dropped a helpful link and said they’d been treating the cube like number shuffles, pushing back on the idea that positions don’t matter. A third voice cheered Prolog’s pattern matching and constraint-style pruning—basically, using rules to skip impossible states—calling it elegant.

Then came the plot twist: a nostalgic bomb about getting a cease & desist after releasing a free Rubik’s app on the Play Store. Cue jokes about “cube lawyers speedrunning a solve” and quips that four face turns to reset is “also how Mondays work.” It’s math meets puzzles meets legal drama, and the community made it a show.

Key Points

  • A 2×2 Rubik’s Cube is modeled in Prolog using positions of 8 corners and a three-component orientation per piece.
  • Face turns F, U, and R are defined with explicit orientation transformations (F: [0,1,2]→[1,0,2], U: [0,2,1], R: [2,0,1]).
  • The cube state is represented via a cube/2 predicate with a provided initial configuration.
  • Prolog’s move predicates (e.g., movef) support inverse operations via argument reversal, enabling bidirectional computation.
  • Iterating F shows the cube returns to the initial state after four turns; an order predicate confirms the operation order is 4.

Hottest takes

"a rubiks cube can be represented by <i>only</i> the orientations of the pieces" — phkahler
"Fun article! Makes me want to play with prolog again." — taeric
"OT: The time between\nreleasing a free Rubik's cube program to play store and receiving a cease &amp; desist has always impressed me." — nurettin
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.