Skip to content

Instantly share code, notes, and snippets.

@kirjavascript
Created November 1, 2022 18:54
Show Gist options
  • Save kirjavascript/a221b9c22e8f16d45f72795646b243e9 to your computer and use it in GitHub Desktop.
Save kirjavascript/a221b9c22e8f16d45f72795646b243e9 to your computer and use it in GitHub Desktop.
weird rubik sim
S = `
UUU
UUU
UUU
LLLFFFRRRBBB
LLLFFFRRRBBB
LLLFFFRRRBBB
DDD
DDD
DDD
`
I = 'UFRBLDxyz';
P = [6,3,0,7,4,1,8,5,2];
// moves
M = process.argv.slice(2).join('').split(/(\ww?\d?'?)/).filter(d=>d.trim());
// optional? remove whitespace
s = S.replace(/\s+/g,'')
U=_=>{
s=P.map(d=>s[d]).join``+s[$='slice'](12,21)+s[$](9,12)+s[$](21)
}
x=_=>{
s=[...'ÀÁÂÌÍÎØÙÚ¿Ë×áâãÛÏü»º¾ÊÖäåæÜП·½ÉÕçèéÝÑŶµ´àßÞÔÓÒÈÇÆ'].map(d=>s[d.charCodeAt()-180]).join``;
};
y=_=>{
s=P.map(d=>s[d]).join``+[0,12,24].flatMap(_=>[[q=12+_,21+_],[9+_,q]]).map(d=>s.slice(...d)).join``+[...P].reverse().map(d=>s[d+45]).join``
};
z=_=>m[8];
m=[
[U],
[x,U,x,x,x],
[y,y,y,x,x,x,U,x,y],
[x,x,x,U,x],
[z,U,z,z,z],
[x,x,U,x,x],
[x],
[y],
[x,y,x,x,x],
];
// execute moves
M.map(d=>{
A=_=>m[I.indexOf(d[0])].map(d=>d());
A();d[1]=="'"?(A(),A()):d[1]&&A();
});
// use mask to get output
i = 0; O = S.replace(/\S/g,_=>s[i++])
// colours
console.log(O.replace(/\S/g,_=>'\x1b['+[47,42,41,44,45,43][I.indexOf(_)]+'m'+_+'\x1b[0m'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment