Created
October 28, 2014 04:23
-
-
Save hantuzun/bd0a3c7c7e7665e40a62 to your computer and use it in GitHub Desktop.
A rubik's cube simulator. I wrote that during the IEEEXtreme 5.0 in 2011. The question can be found here: http://zaidpirwani.com/wp-content/uploads/downloads/2012/11/ieee-xtreme-6.0-faq-sample-questions.pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
char u[3][3]; | |
char l[3][3]; | |
char f[3][3]; | |
char r[3][3]; | |
char b[3][3]; | |
char d[3][3]; | |
char temp[3]; | |
void U() | |
{ | |
int i; | |
for(i = 0; i < 3; i++) | |
temp[i] = f[0][i]; | |
for(i = 0; i < 3; i++) | |
f[0][i] = r[0][i]; | |
for(i = 0; i < 3; i++) | |
r[0][i] = b[0][i]; | |
for(i = 0; i < 3; i++) | |
b[0][i] = l[0][i]; | |
for(i = 0; i < 3; i++) | |
l[0][i] = temp[i]; | |
} | |
void L() | |
{ | |
int i; | |
for(i = 0; i < 3; i++) | |
temp[i] = f[i][0]; | |
for(i = 0; i < 3; i++) | |
f[i][0] = u[0][2-i]; | |
for(i = 0; i < 3; i++) | |
u[0][i] = b[i][2]; | |
for(i = 0; i < 3; i++) | |
d[0][i] = b[2-i][2]; | |
for(i = 0; i < 3; i++) | |
d[0][i] = f[i][0]; | |
for(i = 0; i < 3; i++) | |
d[0][i] = temp[i]; | |
} | |
void F() | |
{ | |
int i; | |
for(i = 0; i < 3; i++); | |
} | |
void R() | |
{ | |
int i; | |
for(i = 0; i < 3; i++); | |
} | |
void B() | |
{ | |
int i; | |
for(i = 0; i < 3; i++); | |
} | |
void D() | |
{ | |
int i; | |
for(i = 0; i < 3; i++); | |
} | |
//////////////////////////////////////////////// MAIN FUNCTION /////////////////////////////////////////////// | |
int main() | |
{ | |
int x; | |
int y; | |
int i; | |
int j; | |
char u0; | |
char l0; | |
char f0; | |
char r0; | |
char b0; | |
char d0; | |
scanf("%c", &u0); | |
for(i = 0; i < 3; i++) | |
{ | |
for(j = 0; j < 3; j++) | |
{ | |
u[i][j] = u0; | |
} | |
} | |
scanf("%c", &l0); | |
for(i = 0; i < 3; i++) | |
{ | |
for(j = 0; j < 3; j++) | |
{ | |
l[i][j] = l0; | |
} | |
} | |
scanf("%c", &f0); | |
for(i = 0; i < 3; i++) | |
{ | |
for(j = 0; j < 3; j++) | |
{ | |
f[i][j] = f0; | |
} | |
} | |
scanf("%c", &r0); | |
for(i = 0; i < 3; i++) | |
{ | |
for(j = 0; j < 3; j++) | |
{ | |
r[i][j] = r0; | |
} | |
} | |
scanf("%c", &b0); | |
for(i = 0; i < 3; i++) | |
{ | |
for(j = 0; j < 3; j++) | |
{ | |
b[i][j] = b0; | |
} | |
} | |
scanf("%c", &d0); | |
for(i = 0; i < 3; i++) | |
{ | |
for(j = 0; j < 3; j++) | |
{ | |
d[i][j] = d0; | |
} | |
} | |
char str[100]; | |
scanf("%s", &str); | |
int k; | |
char hist = 0; | |
for(i = 0, j = 0; i < strlen(str) ; i++) | |
{ | |
switch(str[i]) | |
{ | |
case 'U': U(); hist = str[i]; break; | |
case 'L': L(); hist = str[i]; break; | |
case 'F': F(); hist = str[i]; break; | |
case 'R': R(); hist = str[i]; break; | |
case 'B': B(); hist = str[i]; break; | |
case 'D': D(); hist = str[i]; break; | |
default : break; | |
} | |
if( '1' <= str[i] && str[i] <= '9') | |
{ | |
for(k = 0; k < str[i]-49; k++) | |
{ | |
switch(hist) | |
{ | |
case 'U': U(); break; | |
case 'L': L(); break; | |
case 'F': F(); break; | |
case 'R': R(); break; | |
case 'B': B(); break; | |
case 'D': D(); break; | |
default : break; | |
} | |
} | |
} | |
if( str[i] == '\'') | |
{ | |
for(k = 0; k < 2; k++) | |
{ | |
switch(hist) | |
{ | |
case 'U': U(); break; | |
case 'L': L(); break; | |
case 'F': F(); break; | |
case 'R': R(); break; | |
case 'B': B(); break; | |
case 'D': D(); break; | |
default : break; | |
} | |
} | |
} | |
} | |
for(x = 0; x < 3; x++) | |
{ | |
for(y = 0; y < 3; y++) | |
{ | |
printf("%c ", f[x][y]); | |
} | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment