sourcedemos/eigencube/eigencube.xtl
1⍝!/usr/bin/env xetal
2⍝# Eigencube: a Rubik's cube solved by linear algebra, a port of Steffen
3⍝# Smolka's eigencube.py (github.com/smolkaj/eigencube, MIT). Each of
4⍝# the 26 cubelets is the integer point c of {-1, 0, 1}^3 where it sits
5⍝# in the solved cube and carries a rotation matrix R: it sits now at
6⍝# R c. A quarter turn of the face with outward normal v moves the
7⍝# cubelets with v . (R c) > 0 by one matrix product. The model and the
8⍝# solver are the Eigencube library of X_eTaL-libraries (pinned in
9⍝# LIBRARIES_COMMIT, read from work/libraries by "just libraries"); this
10⍝# program scrambles a cube and solves it with it.
11
12ᵉᶜ⁼u̲se< "Eigencube"
13
14⍝## A scramble
15
16⍝ 20 random moves ("just run eigencube" draws a new one each time; the
17⍝ tests run "xetal run --seed 1"), in the usual notation.
18sc ← r̲oll! 20 r̲eshape 12
19"scramble: " c̲at ᵉᶜn̲ame sc
20x ← sc ᵉᶜd̲o ᵉᶜsolved
21⍝ Its stickers, a face per row (U D F B R L), each cell the face its
22⍝ color belongs on: 1 to 6, white, yellow, green, blue, red, orange.
23ᵉᶜs̲tickers x
24
25⍝## Solved
26
27(sol, lens, e) ← 1 ᵉᶜs̲olve x
28"solution: " c̲at ᵉᶜn̲ame sol
29"moves: " c̲at f̲ormat t̲ally sol
30⍝ The moves each stage took: the top layer a cubelet at a time
31⍝ (stages 1 to 9), the middle layer (10 to 17), the bottom edges (18
32⍝ to 25) and the bottom corners' places (26 to 29), then the
33⍝ endgame's corner twists.
34lens c̲at e
35⍝ After the solution: every face one color.
36ᵉᶜs̲tickers sol ᵉᶜd̲o x
37"solved: " c̲at f̲ormat ᵉᶜs̲olved? sol ᵉᶜd̲o x