Initial commit
This commit is contained in:
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: gcc build active file",
|
||||
"command": "/usr/bin/gcc",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,110 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define W 0
|
||||
#define Y 1
|
||||
#define O 2
|
||||
#define R 3
|
||||
#define B 4
|
||||
#define G 5
|
||||
|
||||
|
||||
|
||||
typedef struct Cube {
|
||||
int front[3][3];
|
||||
int back[3][3];
|
||||
int top[3][3];
|
||||
int bottom[3][3];
|
||||
int right[3][3];
|
||||
int left[3][3];
|
||||
} Cube;
|
||||
|
||||
|
||||
void initialize(Cube *cube) {
|
||||
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
cube->front[i][j] = W;
|
||||
cube->back[i][j] = Y;
|
||||
cube->top[i][j] = O;
|
||||
cube->bottom[i][j] = R;
|
||||
cube->right[i][j] = B;
|
||||
cube->left[i][j] = G;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print(Cube *cube) {
|
||||
char colors[] = {'W', 'Y', 'O', 'R', 'B', 'G'};
|
||||
|
||||
printf(" %c, %c, %c, \n", colors[cube->back[0][0]], colors[cube->back[0][1]], colors[cube->back[0][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->back[1][0]], colors[cube->back[1][1]], colors[cube->back[1][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->back[2][0]], colors[cube->back[2][1]], colors[cube->back[2][2]]);
|
||||
|
||||
printf("\n");
|
||||
printf(" %c, %c, %c, \n", colors[cube->top[0][0]], colors[cube->top[0][1]], colors[cube->top[0][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->top[1][0]], colors[cube->top[1][1]], colors[cube->top[1][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->top[2][0]], colors[cube->top[2][1]], colors[cube->top[2][2]]);
|
||||
|
||||
printf("\n");
|
||||
printf("%c, %c, %c, ", colors[cube->left[0][0]], colors[cube->left[0][1]], colors[cube->left[0][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->front[0][0]], colors[cube->front[0][1]], colors[cube->front[0][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->right[0][0]], colors[cube->right[0][1]], colors[cube->right[0][2]]);
|
||||
|
||||
printf("\n");
|
||||
printf("%c, %c, %c, ", colors[cube->left[1][0]], colors[cube->left[1][1]], colors[cube->left[1][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->front[1][0]], colors[cube->front[1][1]], colors[cube->front[1][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->right[1][0]], colors[cube->right[1][1]], colors[cube->right[1][2]]);
|
||||
|
||||
printf("\n");
|
||||
printf("%c, %c, %c, ", colors[cube->left[2][0]], colors[cube->left[2][1]], colors[cube->left[2][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->front[2][0]], colors[cube->front[2][1]], colors[cube->front[2][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->right[2][0]], colors[cube->right[2][1]], colors[cube->right[2][2]]);
|
||||
|
||||
printf("\n\n");
|
||||
printf(" %c, %c, %c, \n", colors[cube->bottom[0][0]], colors[cube->bottom[0][1]], colors[cube->bottom[0][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->bottom[1][0]], colors[cube->bottom[1][1]], colors[cube->bottom[1][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->bottom[2][0]], colors[cube->bottom[2][1]], colors[cube->bottom[2][2]]);
|
||||
|
||||
printf("----------------------------\n");
|
||||
}
|
||||
|
||||
void rotate_face(int mat[3][3]) {
|
||||
int temp[3][3];
|
||||
|
||||
for(int i=0;i<3;i++){
|
||||
for(int j=0;j<3;j++){
|
||||
temp[j][3-1-i] = mat[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<3;i++) {
|
||||
for(int j=0;j<3;j++) {
|
||||
mat[i][j] = temp[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rotate_edge_corner (Cube *cube, char side[10]) {
|
||||
// TODO
|
||||
// Note: unify rotate_edge_corner with rotate_face
|
||||
}
|
||||
|
||||
void main (){
|
||||
|
||||
Cube cube;
|
||||
initialize(&cube);
|
||||
|
||||
cube.back[0][1]=3;
|
||||
cube.back[2][2]=4;
|
||||
|
||||
print(&cube);
|
||||
|
||||
rotate_90(cube.back);
|
||||
|
||||
print(&cube);
|
||||
|
||||
rotate_90(cube.back);
|
||||
|
||||
print(&cube);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define UP 0
|
||||
#define DOWN 1
|
||||
#define LEFT 2
|
||||
#define RIGHT 3
|
||||
#define FRONT 4
|
||||
#define BACK 5
|
||||
|
||||
|
||||
|
||||
typedef struct Cube {
|
||||
int x, y, z;
|
||||
char sticker[6];
|
||||
} Cube;
|
||||
|
||||
|
||||
void initialize(Cube* array, int pos[3][3][3]) {
|
||||
for (int i=0; i<27; i++) {
|
||||
// Calcolo le coordinate in base agli indici e le assegno ai cubetti
|
||||
int x=i%3;
|
||||
int y=(i/9);
|
||||
int z=(i/3)%3;
|
||||
|
||||
array[i].x=x;
|
||||
array[i].y=y;
|
||||
array[i].z=z;
|
||||
|
||||
|
||||
// Inizializzo tutti gli sticker e associo i colori ai cubetti
|
||||
array[i].sticker[DOWN] = 'W';
|
||||
array[i].sticker[UP] = 'Y';
|
||||
array[i].sticker[LEFT] = 'B';
|
||||
array[i].sticker[RIGHT] = 'G';
|
||||
array[i].sticker[BACK] = 'O';
|
||||
array[i].sticker[FRONT] = 'R';
|
||||
|
||||
|
||||
// Mi salvo che cubetto ho per ogni coordinata
|
||||
pos[x][y][z]=i;
|
||||
}
|
||||
}
|
||||
|
||||
void print(Cube* array, int pos[3][3][3]) {
|
||||
printf(" %c %c %c\n %c %c %c\n %c %c %c", array[pos[0][2][2]].sticker[BACK], array[pos[1][2][2]].sticker[BACK], array[pos[2][2][2]].sticker[BACK], array[pos[0][1][2]].sticker[BACK], array[pos[1][1][2]].sticker[BACK], array[pos[2][1][2]].sticker[BACK], array[pos[0][0][2]].sticker[BACK], array[pos[1][0][2]].sticker[BACK], array[pos[2][0][2]].sticker[BACK]);
|
||||
|
||||
printf("\n\n %c %c %c\n %c %c %c\n %c %c %c", array[pos[0][0][2]].sticker[UP], array[pos[1][0][2]].sticker[UP], array[pos[2][0][2]].sticker[UP], array[pos[0][0][1]].sticker[UP], array[pos[1][0][1]].sticker[UP], array[pos[2][0][1]].sticker[UP], array[pos[0][0][0]].sticker[UP], array[pos[1][0][0]].sticker[UP], array[pos[2][0][0]].sticker[UP]);
|
||||
|
||||
printf("\n\n%c %c %c %c %c %c %c %c %c", array[pos[0][0][2]].sticker[LEFT], array[pos[0][0][1]].sticker[LEFT], array[pos[0][0][0]].sticker[LEFT], array[pos[0][0][0]].sticker[FRONT], array[pos[1][0][0]].sticker[FRONT], array[pos[2][0][0]].sticker[FRONT], array[pos[2][0][0]].sticker[RIGHT], array[pos[2][0][1]].sticker[RIGHT], array[pos[2][0][2]].sticker[RIGHT]);
|
||||
printf("\n%c %c %c %c %c %c %c %c %c", array[pos[0][1][2]].sticker[LEFT], array[pos[0][1][1]].sticker[LEFT], array[pos[0][1][0]].sticker[LEFT], array[pos[0][1][0]].sticker[FRONT], array[pos[1][1][0]].sticker[FRONT], array[pos[2][1][0]].sticker[FRONT], array[pos[2][1][0]].sticker[RIGHT], array[pos[2][1][1]].sticker[RIGHT], array[pos[2][1][2]].sticker[RIGHT]);
|
||||
printf("\n%c %c %c %c %c %c %c %c %c", array[pos[0][2][2]].sticker[LEFT], array[pos[0][2][1]].sticker[LEFT], array[pos[0][2][0]].sticker[LEFT], array[pos[0][2][0]].sticker[FRONT], array[pos[1][2][0]].sticker[FRONT], array[pos[2][2][0]].sticker[FRONT], array[pos[2][2][0]].sticker[RIGHT], array[pos[2][2][1]].sticker[RIGHT], array[pos[2][2][2]].sticker[RIGHT]);
|
||||
|
||||
printf("\n\n %c %c %c\n %c %c %c\n %c %c %c\n\n\n\n", array[pos[0][2][0]].sticker[DOWN], array[pos[1][2][0]].sticker[DOWN], array[pos[2][2][0]].sticker[DOWN], array[pos[0][2][1]].sticker[DOWN], array[pos[1][2][1]].sticker[DOWN], array[pos[2][2][1]].sticker[DOWN], array[pos[0][2][2]].sticker[DOWN], array[pos[1][2][2]].sticker[DOWN], array[pos[2][2][2]].sticker[DOWN]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void rotate(Cube* array, int pos[3][3][3], char rotazione) {
|
||||
int involved_cubes[9];
|
||||
int index=0;
|
||||
int tmp_x, tmp_y, tmp_z;
|
||||
|
||||
// z=0
|
||||
if (rotazione == 'F') {
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
involved_cubes[index]=pos[i][j][0];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
for (index=0; index<9; index++) {
|
||||
int i=involved_cubes[index];
|
||||
tmp_x = array[i].x;
|
||||
tmp_y = array[i].y;
|
||||
|
||||
array[i].x=2-tmp_y;
|
||||
array[i].y=tmp_x;
|
||||
|
||||
pos[array[i].x][array[i].y][0]=i;
|
||||
|
||||
|
||||
|
||||
char tmp = array[i].sticker[UP];
|
||||
array[i].sticker[UP] = array[i].sticker[LEFT];
|
||||
array[i].sticker[LEFT] = array[i].sticker[DOWN];
|
||||
array[i].sticker[DOWN] = array[i].sticker[RIGHT];
|
||||
array[i].sticker[RIGHT] = tmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// z=2
|
||||
if (rotazione == 'B') {
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
involved_cubes[index]=pos[i][j][2];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
for (index=0; index<9; index++) {
|
||||
int i=involved_cubes[index];
|
||||
tmp_x = array[i].x;
|
||||
tmp_y = array[i].y;
|
||||
|
||||
array[i].x=tmp_y;
|
||||
array[i].y=2-tmp_x;
|
||||
|
||||
pos[array[i].x][array[i].y][2]=i;
|
||||
|
||||
|
||||
|
||||
char tmp = array[i].sticker[DOWN];
|
||||
array[i].sticker[DOWN] = array[i].sticker[LEFT];
|
||||
array[i].sticker[LEFT] = array[i].sticker[UP];
|
||||
array[i].sticker[UP] = array[i].sticker[RIGHT];
|
||||
array[i].sticker[RIGHT] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// y=0
|
||||
if (rotazione == 'U') {
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
involved_cubes[index]=pos[i][0][j];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
for (index=0; index<9; index++) {
|
||||
int i=involved_cubes[index];
|
||||
tmp_x = array[i].x;
|
||||
tmp_z = array[i].z;
|
||||
|
||||
array[i].x=tmp_z;
|
||||
array[i].z=2-tmp_x;
|
||||
|
||||
pos[array[i].x][0][array[i].z]=i;
|
||||
|
||||
|
||||
|
||||
char tmp = array[i].sticker[FRONT];
|
||||
array[i].sticker[FRONT] = array[i].sticker[RIGHT];
|
||||
array[i].sticker[RIGHT] = array[i].sticker[BACK];
|
||||
array[i].sticker[BACK] = array[i].sticker[LEFT];
|
||||
array[i].sticker[LEFT] = tmp;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// y=2
|
||||
if (rotazione == 'D') {
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
involved_cubes[index]=pos[i][2][j];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
for (index=0; index<9; index++) {
|
||||
int i=involved_cubes[index];
|
||||
tmp_x = array[i].x;
|
||||
tmp_z = array[i].z;
|
||||
|
||||
array[i].x=2-tmp_z;
|
||||
array[i].z=tmp_x;
|
||||
|
||||
pos[array[i].x][2][array[i].z]=i;
|
||||
|
||||
|
||||
|
||||
char tmp = array[i].sticker[FRONT];
|
||||
array[i].sticker[FRONT] = array[i].sticker[LEFT];
|
||||
array[i].sticker[LEFT] = array[i].sticker[BACK];
|
||||
array[i].sticker[BACK] = array[i].sticker[RIGHT];
|
||||
array[i].sticker[RIGHT] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// x=0
|
||||
if (rotazione == 'L') {
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
involved_cubes[index]=pos[0][i][j];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
for (index=0; index<9; index++) {
|
||||
int i=involved_cubes[index];
|
||||
tmp_y = array[i].y;
|
||||
tmp_z = array[i].z;
|
||||
|
||||
array[i].y=2-tmp_z;
|
||||
array[i].z=tmp_y;
|
||||
|
||||
pos[0][array[i].y][array[i].z]=i;
|
||||
|
||||
|
||||
|
||||
char tmp = array[i].sticker[UP];
|
||||
array[i].sticker[UP] = array[i].sticker[BACK];
|
||||
array[i].sticker[BACK] = array[i].sticker[DOWN];
|
||||
array[i].sticker[DOWN] = array[i].sticker[FRONT];
|
||||
array[i].sticker[FRONT] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// x=2
|
||||
if (rotazione == 'R') {
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
involved_cubes[index]=pos[2][i][j];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
for (index=0; index<9; index++) {
|
||||
int i=involved_cubes[index];
|
||||
tmp_y = array[i].y;
|
||||
tmp_z = array[i].z;
|
||||
|
||||
array[i].y=tmp_z;
|
||||
array[i].z=2-tmp_y;
|
||||
|
||||
pos[2][array[i].y][array[i].z]=i;
|
||||
|
||||
|
||||
|
||||
char tmp = array[i].sticker[UP];
|
||||
array[i].sticker[UP] = array[i].sticker[FRONT];
|
||||
array[i].sticker[FRONT] = array[i].sticker[DOWN];
|
||||
array[i].sticker[DOWN] = array[i].sticker[BACK];
|
||||
array[i].sticker[BACK] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
Cube array[27];
|
||||
int pos[3][3][3];
|
||||
|
||||
initialize(array, pos);
|
||||
|
||||
|
||||
rotate(array, pos, 'F');
|
||||
print(array, pos);
|
||||
|
||||
rotate(array, pos, 'U');
|
||||
print(array, pos);
|
||||
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define W 0
|
||||
#define Y 1
|
||||
#define O 2
|
||||
#define R 3
|
||||
#define B 4
|
||||
#define G 5
|
||||
|
||||
|
||||
|
||||
typedef struct Cube {
|
||||
int front[3][3];
|
||||
int back[3][3];
|
||||
int top[3][3];
|
||||
int bottom[3][3];
|
||||
int right[3][3];
|
||||
int left[3][3];
|
||||
} Cube;
|
||||
|
||||
|
||||
void initialize(Cube *cube) {
|
||||
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
cube->front[i][j] = W;
|
||||
cube->back[i][j] = Y;
|
||||
cube->top[i][j] = O;
|
||||
cube->bottom[i][j] = R;
|
||||
cube->right[i][j] = B;
|
||||
cube->left[i][j] = G;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print(Cube *cube) {
|
||||
char colors[] = {'W', 'Y', 'O', 'R', 'B', 'G'};
|
||||
|
||||
printf(" %c, %c, %c, \n", colors[cube->back[0][0]], colors[cube->back[0][1]], colors[cube->back[0][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->back[1][0]], colors[cube->back[1][1]], colors[cube->back[1][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->back[2][0]], colors[cube->back[2][1]], colors[cube->back[2][2]]);
|
||||
|
||||
printf("\n");
|
||||
printf(" %c, %c, %c, \n", colors[cube->top[0][0]], colors[cube->top[0][1]], colors[cube->top[0][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->top[1][0]], colors[cube->top[1][1]], colors[cube->top[1][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->top[2][0]], colors[cube->top[2][1]], colors[cube->top[2][2]]);
|
||||
|
||||
printf("\n");
|
||||
printf("%c, %c, %c, ", colors[cube->left[0][0]], colors[cube->left[0][1]], colors[cube->left[0][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->front[0][0]], colors[cube->front[0][1]], colors[cube->front[0][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->right[0][0]], colors[cube->right[0][1]], colors[cube->right[0][2]]);
|
||||
|
||||
printf("\n");
|
||||
printf("%c, %c, %c, ", colors[cube->left[1][0]], colors[cube->left[1][1]], colors[cube->left[1][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->front[1][0]], colors[cube->front[1][1]], colors[cube->front[1][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->right[1][0]], colors[cube->right[1][1]], colors[cube->right[1][2]]);
|
||||
|
||||
printf("\n");
|
||||
printf("%c, %c, %c, ", colors[cube->left[2][0]], colors[cube->left[2][1]], colors[cube->left[2][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->front[2][0]], colors[cube->front[2][1]], colors[cube->front[2][2]]);
|
||||
printf("%c, %c, %c, ", colors[cube->right[2][0]], colors[cube->right[2][1]], colors[cube->right[2][2]]);
|
||||
|
||||
printf("\n\n");
|
||||
printf(" %c, %c, %c, \n", colors[cube->bottom[0][0]], colors[cube->bottom[0][1]], colors[cube->bottom[0][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->bottom[1][0]], colors[cube->bottom[1][1]], colors[cube->bottom[1][2]]);
|
||||
printf(" %c, %c, %c, \n", colors[cube->bottom[2][0]], colors[cube->bottom[2][1]], colors[cube->bottom[2][2]]);
|
||||
|
||||
printf("----------------------------\n");
|
||||
}
|
||||
|
||||
void rotate_90(int mat[3][3]) {
|
||||
|
||||
// Rotate the single face
|
||||
int temp[3][3];
|
||||
|
||||
for(int i=0;i<3;i++){
|
||||
for(int j=0;j<3;j++){
|
||||
temp[j][3-1-i] = mat[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<3;i++) {
|
||||
for(int j=0;j<3;j++) {
|
||||
mat[i][j] = temp[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Rotate the other 4 faces
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main (){
|
||||
|
||||
Cube cube;
|
||||
initialize(&cube);
|
||||
|
||||
cube.back[0][1]=3;
|
||||
cube.back[2][2]=4;
|
||||
|
||||
print(&cube);
|
||||
|
||||
//rotate_90(cube.back);
|
||||
|
||||
print(&cube);
|
||||
|
||||
// rotate_90(cube.back);
|
||||
|
||||
print(&cube);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user