C, 1715 1709 1686 1336 1328 bytes
25 bytes saved thanks to @KevinCruijssen!
No answers so far, so I decided to put my own solution.
#define m(a,b,c,d)t[c][d]=r[a][b];
#define n(a)m(a,0,a,2)m(a,1,a,5)m(a,2,a,8)m(a,3,a,1)m(a,5,a,7)m(a,6,a,0)m(a,7,a,3)m(a,8,a,6)
#define y memcpy
typedef char R[6][9];R t;F(R r){y(t,r,54);n(0)m(4,6,1,0)m(4,7,1,3)m(4,8,1,6)m(1,0,5,0)m(1,3,5,1)m(1,6,5,2)m(5,0,3,2)m(5,1,3,5)m(5,2,3,8)m(3,2,4,6)m(3,5,4,7)m(3,8,4,8)y(r,t,54);}B(R r){y(t,r,54);n(2)m(1,2,4,0)m(1,5,4,1)m(1,8,4,2)m(3,0,5,6)m(3,3,5,7)m(3,6,5,8)m(4,0,3,6)m(4,1,3,3)m(4,2,3,0)m(5,6,1,8)m(5,7,1,5)m(5,8,1,2)y(r,t,54);}L(R r){y(t,r,54);n(3)m(0,0,5,0)m(0,3,5,3)m(0,6,5,6)m(2,2,4,6)m(2,5,4,3)m(2,8,4,0)m(4,0,0,0)m(4,3,0,3)m(4,6,0,6)m(5,0,2,8)m(5,3,2,5)m(5,6,2,2)y(r,t,54);}E(R r){y(t,r,54);n(1)m(0,2,4,2)m(0,5,4,5)m(0,8,4,8)m(5,2,0,2)m(5,5,0,5)m(5,8,0,8)m(4,2,2,6)m(4,5,2,3)m(4,8,2,0)m(2,0,5,8)m(2,3,5,5)m(2,6,5,2)y(r,t,54);}U(R r){y(t,r,54);n(4)m(0,0,3,0)m(0,1,3,1)m(0,2,3,2)m(1,0,0,0)m(1,1,0,1)m(1,2,0,2)m(2,0,1,0)m(2,1,1,1)m(2,2,1,2)m(3,0,2,0)m(3,1,2,1)m(3,2,2,2)y(r,t,54);}D(R r){y(t,r,54);n(5)m(0,6,1,6)m(0,7,1,7)m(0,8,1,8)m(1,6,2,6)m(1,7,2,7)m(1,8,2,8)m(2,6,3,6)m(2,7,3,7)m(2,8,3,8)m(3,6,0,6)m(3,7,0,7)m(3,8,0,8)y(r,t,54);}a,b,c,d,e,o,p,l;f(char*z,R s){char c[6]="RGOBYW";for(;b<7;b++)for(a=0;a<10;)s[b][a++]=c[b];for(l=strlen(z);l-->0;){d=*z++;if(d-32){e=*z++;if(*z++-32)*z++;o=e-50?e-39?1:3:2;for(p=0;p++<o;)d-70?d-66?d-76?d-82?d-85?D(s):U(s):E(s):L(s):B(s):F(s);}}}
Try it online!
Ungolfed old version:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
typedef char Tile;
typedef Tile Face[10];
typedef Face Rubik[7];
void main_loop(Rubik);
void rubik_init(Rubik);
void rubik_print(Rubik);
void rotate(Rubik, char, char);
void print_tile(Rubik, int, int);
void F(Rubik);
void B(Rubik);
void L(Rubik);
void R(Rubik);
void U(Rubik);
void D(Rubik);
#define move(a, b, c, d) \
temp[c][d] = rubik[a][b]
#define move_f(a) \
move(a, 1, a, 3); \
move(a, 2, a, 6); \
move(a, 3, a, 9); \
move(a, 4, a, 2); \
move(a, 6, a, 8); \
move(a, 7, a, 1); \
move(a, 8, a, 4); \
move(a, 9, a, 7)
void F(Rubik rubik) {
Rubik temp;
memcpy(temp, rubik, sizeof(Rubik));
move_f(1);
move(5, 7, 2, 1);
move(5, 8, 2, 4);
move(5, 9, 2, 7);
move(2, 1, 6, 1);
move(2, 4, 6, 2);
move(2, 7, 6, 3);
move(6, 1, 4, 3);
move(6, 2, 4, 6);
move(6, 3, 4, 9);
move(4, 3, 5, 7);
move(4, 6, 5, 8);
move(4, 9, 5, 9);
memcpy(rubik, temp, sizeof(Rubik));
}
void B(Rubik rubik) {
Rubik temp;
memcpy(temp, rubik, sizeof(Rubik));
move_f(3);
move(2, 3, 5, 1);
move(2, 6, 5, 2);
move(2, 9, 5, 3);
move(4, 1, 6, 7);
move(4, 4, 6, 8);
move(4, 7, 6, 9);
move(5, 1, 4, 7);
move(5, 2, 4, 4);
move(5, 3, 4, 1);
move(6, 7, 2, 9);
move(6, 8, 2, 6);
move(6, 9, 2, 3);
memcpy(rubik, temp, sizeof(Rubik));
}
void L(Rubik rubik) {
Rubik temp;
memcpy(temp, rubik, sizeof(Rubik));
move_f(4);
move(1, 1, 6, 1);
move(1, 4, 6, 4);
move(1, 7, 6, 7);
move(3, 3, 5, 7);
move(3, 6, 5, 4);
move(3, 9, 5, 1);
move(5, 1, 1, 1);
move(5, 4, 1, 4);
move(5, 7, 1, 7);
move(6, 1, 3, 9);
move(6, 4, 3, 6);
move(6, 7, 3, 3);
memcpy(rubik, temp, sizeof(Rubik));
}
void R(Rubik rubik) {
Rubik temp;
memcpy(temp, rubik, sizeof(Rubik));
move_f(2);
move(1, 3, 5, 3);
move(1, 6, 5, 6);
move(1, 9, 5, 9);
move(6, 3, 1, 3);
move(6, 6, 1, 6);
move(6, 9, 1, 9);
move(5, 3, 3, 7);
move(5, 6, 3, 4);
move(5, 9, 3, 1);
move(3, 1, 6, 9);
move(3, 4, 6, 6);
move(3, 7, 6, 3);
memcpy(rubik, temp, sizeof(Rubik));
}
void U(Rubik rubik) {
Rubik temp;
memcpy(temp, rubik, sizeof(Rubik));
move_f(5);
move(1, 1, 4, 1);
move(1, 2, 4, 2);
move(1, 3, 4, 3);
move(2, 1, 1, 1);
move(2, 2, 1, 2);
move(2, 3, 1, 3);
move(3, 1, 2, 1);
move(3, 2, 2, 2);
move(3, 3, 2, 3);
move(4, 1, 3, 1);
move(4, 2, 3, 2);
move(4, 3, 3, 3);
memcpy(rubik, temp, sizeof(Rubik));
}
void D(Rubik rubik) {
Rubik temp;
memcpy(temp, rubik, sizeof(Rubik));
move_f(6);
move(1, 7, 2, 7);
move(1, 8, 2, 8);
move(1, 9, 2, 9);
move(2, 7, 3, 7);
move(2, 8, 3, 8);
move(2, 9, 3, 9);
move(3, 7, 4, 7);
move(3, 8, 4, 8);
move(3, 9, 4, 9);
move(4, 7, 1, 7);
move(4, 8, 1, 8);
move(4, 9, 1, 9);
memcpy(rubik, temp, sizeof(Rubik));
}
int main(int argc, char *argv[]) {
Rubik rubik;
rubik_init(rubik);
main_loop(rubik);
return 0;
}
void main_loop(Rubik rubik) {
char a, b;
for (;;) {
a=toupper(getchar());
if (a == 'Q') break;
if (a != 10) {
b=toupper(getchar());
if (b != 10) getchar();
rotate(rubik, a, b);
}
rubik_print(rubik);
}
}
void rubik_init(Rubik rubik) {
int i,n;
char c[7] = " RGOBYW";
for (n=1; n<=7; n++)
for (i=1; i<=10; i++)
rubik[n][i] = c[n];
}
void rotate(Rubik rubik, char a, char b){
int i = b == '2' ? 2 : b == '\'' || b == toupper('i') ? 3 : 1;
int j;
for (j=0; j<i; j++)
if (a == 'F') F(rubik);
else if (a == 'B') B(rubik);
else if (a == 'L') L(rubik);
else if (a == 'R') R(rubik);
else if (a == 'U') U(rubik);
else if (a == 'D') D(rubik);
else;
}
void rubik_print(Rubik rubik) {
int i,j,k;
for (i=1; i<=9; i++)
if (i%3==0) {
print_tile(rubik,5,i);
printf("\n");
}
else if (i%3==1) {
printf(" ");
print_tile(rubik,5,i);
}
else
print_tile(rubik,5,i);
printf("\n");
for (k=1; k<=3; k++) {
for (i=3; i<=6; i++) {
for (j=k*3-2; j<=k*3; j++)
print_tile(rubik, i%4+1, j);
printf(" ");
}
printf("\n");
}
printf("\n");
for (i=1; i<=9; i++)
if (i%3==0) {
print_tile(rubik, 6, i);
printf("\n");
}
else if (i%3==1) {
printf(" ");
print_tile(rubik, 6, i);
}
else
print_tile(rubik, 6, i);
}
void print_tile(Rubik rubik, int a, int b) {
switch (rubik[a][b]) {
case 'R':
printf("R");
break;
case 'O':
printf("O");
break;
case 'B':
printf("B");
break;
case 'G':
printf("G");
break;
case 'Y':
printf("Y");
break;
case 'W':
printf("W");
break;
default:
exit(1);
}
}
2Related, related, related. – betseg – 2016-09-06T18:42:18.420
May we choose to choose to re-orient the cube (for example, having White U, Orange F, and Green R)? – primo – 2016-09-07T12:07:51.917
Yes, of course, as long as they're separate and recognizable. – betseg – 2016-09-07T12:09:36.260
Do we need to support
S
,E
,M
,x
,y
,z
,u
/Uw
,d
/Dw
,r
/Rw
,l
/Lw
,f
/Fw
,b
/Bw
moves as well? Or only the default:U
,D
,R
,L
,F
,B
and their counterclockwise variant with apostrophe ('
)? Off-topic: I always wonder with Rubik's Cube related questions, are you also a Twisty Puzzles collector? – Kevin Cruijssen – 2016-09-07T12:27:52.740No, just the 6 standard default moves, counterclockwise variants and 180° variants (like
U2
). Also no, I'm not a collector. – betseg – 2016-09-07T12:32:53.8073@KevinCruijssen Dang, that's a lot of puzzles. – mbomb007 – 2016-09-07T20:08:30.733
@mbomb007 Thanks! :) Funny that you took the effort to look them up in my profile. ;p (For anyone else wondering now: my Twisty Puzzles collection - the collection pictures are actually from a few months ago, I now have one more shelve, which is full again... Really need to make some new pictures, but still have a few puzzles scrambled after my scramble video in February.. Once and never again.. >.>)
– Kevin Cruijssen – 2016-09-07T20:28:27.463Can we have a more lax output format and allow this sort of output?
– MD XF – 2018-01-22T21:16:57.223@MDXF sure, i can't see a reason why not – betseg – 2018-01-22T23:51:21.497