Rubik's Cube in Prolog – Order
37 points
4 days ago
| 5 comments
| medium.com
| HN
phkahler
8 hours ago
[-]
I'm not sure if anyone has noticed, a rubiks cube can be represented by only the orientations of the pieces. You do this by defining their "correct" position in cube coordinates rather than piece coordinates (local about the piece center). In other words you might define a 3d model for each piece in world space assuming the cube as a whole is centered on the origin. With pieces offset from the origin like this, any rotation about an axis will appear to move the piece as well as rotate it. With 24 orientations, you'll find 3 that place a corner in the same position but colors rotated. Similarly edges have 2 orientations for each of 12 locations.

One does need to compute the traditional position of the pieces to determine which ones need to be rotated for a given move, but the total state is significantly reduced.

Tell me this isn't news to the cube world. It cant be. Can it?

reply
DHRicoF
26 minutes ago
[-]
I don't have enough time now to work out how are the movement described in your representation to evaluate its convenience. If you have worked out something, could you share it?

I don't know anything about the cube world as I'm just a noob in this.

reply
spartanatreyu
3 hours ago
[-]
I'm trying to figure out what you're trying to say here.

You didn't really define what "cube coordinates" or "piece coordinates" are.

If you're trying to reduce the size of the state needed to represent the entire state of the cube, you can represent it as the operations needed to transform a solved cube into that state.

Each possible permutation of legal state in a rubiks cube can be achieved in 20 operations (moves) or less.

But that's expensive to calculate if you are only given the target state without the list of operations to generate that state.

It also doesn't let you represent illegal states (e.g. someone has spun a single corner piece on the spot) or know if a given state is illegal without trying to brute-force solve the cube.

Needing to represent the state of a cube without knowing the operations that generate that state is far more useful than being given a state that's already the solution to solve a cube.

reply
dsfiof
8 hours ago
[-]
Unable to fully parse what you are trying to express.

> the total state is significantly reduced.

The minimal "state space" of a rubiks cube is a constant value. Any "reduction" would imply the model being reduced was inefficient.

On the topic of cool "alternative" views of rubiks I recently saw this and thought it was novel.

https://old.reddit.com/r/gifs/comments/z3okyv/the_only_way_t...

reply
wowczarek
7 hours ago
[-]
That link. This is a Celtic Knot and 92 is half of 99. I had to.
reply
timonoko
1 hour ago
[-]
It would be much funnier, if the Cube was at origo. So indexes are {-1,0,+1}. And thus Cube[0,0,0] is empty, or maybe there is a ball with 6 screw-holes in it.
reply
taeric
8 hours ago
[-]
Fun article! Makes me want to play with prolog again.

I put together something looking at a rubik's cube as a permutation of numbers a while back. https://taeric.github.io/cube-permutations-1.html I remember realizing that my representation essentially had some permutations of numbers that it would never hit, but wasn't sure it was worth trying to more directly model the pieces of the cube. Curious if there are advantages here that I'm ignoring.

reply
QuadmasterXLII
7 hours ago
[-]
one nice thing is that if you represent the state as a permutation matrix P, and have a matrix of starting piece locations x, rendering is just Px. Then, for smooth rotation animations, if your move is a permutation M, animation is just expm ( t logm( M)) P x with t going from 0 to 1

I blather about the permutation matrix of a rubiks cube for a long while at https://www.hgreer.com/TwistyPuzzle/

reply
Nora23
6 hours ago
[-]
Prolog's pattern matching makes this elegant. The constraint-based approach for state space pruning is clever.
reply
nurettin
4 hours ago
[-]
OT: The time between releasing a free Rubik's cube program to play store and receiving a cease & desist has always impressed me.
reply