#include #include #include int allsol[1000][6][6][2]; int allsize; #define SIZE (6*6*2*sizeof(int)) int in_all_sol(int s[6][6][2]) { int i; for (i = 0; i < allsize; i++) if (!memcmp(s, allsol[i], SIZE)) return 1; return 0; } void put_in_all(int s[6][6][2]) { if (allsize == 1000) { printf("impossible!\n"); exit(1); } memcpy(allsol[allsize], s, SIZE); allsize++; } int sol[16][6][6][2]; int size; int in_sol(int s[6][6][2]) { if (!in_all_sol(s)) put_in_all(s); int i; for (i = 0; i < size; i++) if (!memcmp(s, sol[i], SIZE)) return 1; return 0; } void put(int s[6][6][2]) { if (size == 16) { printf("impossible!\n"); exit(1); } memcpy(sol[size], s, SIZE); size++; } void normalize(int a[6][6][2], int b[6][6][2]) { int p[18]; int x, y, z; int piece = 1; memset(p, 0, sizeof(p)); for (x = 0; x < 6; x++) for (y = 0; y < 6; y++) for (z = 0; z < 2; z++) { int cur = a[x][y][z]; if (!p[cur-1]) { p[cur-1] = piece; piece++; } b[x][y][z] = p[cur-1]; } } void read_sol(int s[6][6][2]) { int t[6][6][2]; int x, y, z; for (z = 0; z < 2; z++) { for (y = 0; y < 6; y++) { for (x = 0; x < 6; x++) { if (scanf(" %d", &t[x][y][z]) != 1) abort(); } } } normalize(t, s); } void rotate1(int a[6][6][2], int b[6][6][2]) { int x, y, z; /* rotate pi/2 * (a+ib)(cos+isin) = (a+ib)(i) = -b + ia * nx = -y; ny = x; */ for (x = 0; x < 6; x++) for (y = 0; y < 6; y++) for (z = 0; z < 2; z++) { int nx = 5-y; int ny = x; b[nx][ny][z] = a[x][y][z]; } } void rotate2(int a[6][6][2], int b[6][6][2]) { int x, y, z; /* pi for (y,z): ny = -y; nz = -z; */ for (x = 0; x < 6; x++) for (y = 0; y < 6; y++) for (z = 0; z < 2; z++) { int ny = 5-y; int nz = 1-z; b[x][ny][nz] = a[x][y][z]; } } void mirror(int a[6][6][2], int b[6][6][2]) { int x, y, z; /* nz = -z */ for (x = 0; x < 6; x++) for (y = 0; y < 6; y++) for (z = 0; z < 2; z++) { int nz = 1-z; b[x][y][nz] = a[x][y][z]; } } /* feed sol with all unique rotations/symmetries of s */ void feed_sol(int s[6][6][2]) { int s2[6][6][2]; int s3[6][6][2]; int sn[6][6][2]; int sx[6][6][2]; int i; memcpy(s2, s, SIZE); for (i = 0; i < 3; i++) { rotate1(s2, s3); normalize(s3, sn); if (!in_sol(sn)) put(sn); } rotate2(s, s3); normalize(s3, s2); for (i = 0; i < 4; i++) { rotate1(s2, s3); normalize(s3, sn); if (!in_sol(sn)) put(sn); } mirror(s, s3); normalize(s3, sx); memcpy(s2, sx, SIZE); for (i = 0; i < 4; i++) { rotate1(s2, s3); normalize(s3, sn); if (!in_sol(sn)) put(sn); } rotate2(sx, s3); normalize(s3, s2); for (i = 0; i < 4; i++) { rotate1(s2, s3); normalize(s3, sn); if (!in_sol(sn)) put(sn); memcpy(s2, s3, SIZE); } } void p(int busy[6][6][2]) { int x, y, z; printf("------------------"); for (z = 0; z < 2; z++) { for (y = 0; y < 6; y++) { for (x = 0; x < 6; x++) { printf(" %2.2d", busy[x][y][z]); } } } printf("\n"); } int main(void) { int s[6][6][2]; int i; for (i = 0; i < 136; i++) { read_sol(s); size = 0; feed_sol(s); printf("%d %d\n", i, size); //int j; for (j = 0; j < size; j++) p(sol[j]); } printf("allsize %d\n", allsize); return 0; }