#include #include int solutions[480][7]; int symmetry[480]; #define X_AXIS 0 #define Y_AXIS 1 #define Z_AXIS 2 int symmetrize(int c, int axis) { int cube[3][3][3]; int bit; int ret; int x, y, z; /* change representation of the solution, put it in the 3x3x3 cube */ for (x = 0; x < 3; x++) for (y = 0; y < 3; y++) for (z = 0; z < 3; z++) { bit = x * 9 + y * 3 + z; if (c & (1 << bit)) cube[x][y][z] = 1; else cube[x][y][z] = 0; } /* collect the bits again, but with a symmetry around given axis */ ret = 0; for (x = 0; x < 3; x++) for (y = 0; y < 3; y++) for (z = 0; z < 3; z++) { bit = x * 9 + y * 3 + z; switch (axis) { case X_AXIS: if (cube[2-x][y][z]) ret |= 1 << bit; break; case Y_AXIS: if (cube[x][2-y][z]) ret |= 1 << bit; break; case Z_AXIS: if (cube[x][y][2-z]) ret |= 1 << bit; break; } } /* note: we could do this in one loop, but it would be maybe less readable */ return ret; } void compute_symmetry(int i, int axis) { int pieces_symmetry[7]; int j; pieces_symmetry[0] = symmetrize(solutions[i][0], axis); pieces_symmetry[1] = symmetrize(solutions[i][1], axis); pieces_symmetry[2] = symmetrize(solutions[i][2], axis); pieces_symmetry[3] = symmetrize(solutions[i][3], axis); pieces_symmetry[4] = symmetrize(solutions[i][6], axis); /* piece 7 -> 5 */ pieces_symmetry[5] = symmetrize(solutions[i][5], axis); pieces_symmetry[6] = symmetrize(solutions[i][4], axis); /* piece 5 -> 7 */ /* look for the symmetrical solution, it has to exist! */ for (j = 0; j < 480; j++) { int k; for (k = 0; k < 7; k++) if (solutions[j][k] != pieces_symmetry[k]) break; if (k == 7) { symmetry[i] = j; break; } } if (j == 480) { printf("what? no symmetry found for solution %d?\n", i); exit(1); } } void read_solutions(void) { int i; int j; int x; for (i = 0; i < 480; i++) for (j = 0; j < 7; j++) { if (scanf("%x", &x) != 1) { printf("error\n"); exit(1); } solutions[i][j] = x; } } void check_symmetry(int i) { int j = symmetry[i]; if (symmetry[j] != i) { printf("uh oh, symmetry fails!\n"); exit(1); } } int main(void) { int i; read_solutions(); /* verify with X axis */ printf("x\n"); for (i = 0; i < 480; i++) compute_symmetry(i, X_AXIS); for (i = 0; i < 480; i++) check_symmetry(i); /* verify with Y axis */ printf("y\n"); for (i = 0; i < 480; i++) compute_symmetry(i, Y_AXIS); for (i = 0; i < 480; i++) check_symmetry(i); /* verify with Z axis */ printf("z\n"); for (i = 0; i < 480; i++) compute_symmetry(i, Z_AXIS); for (i = 0; i < 480; i++) check_symmetry(i); return 0; }