16namespace layer1_foundations {
17namespace combinatorics {
19static void pentomino_puzzle_compute_image_function(data_structures::set_of_sets *S,
20 void *compute_image_data,
int elt_idx,
21 int gen_idx,
int &idx_of_image,
int verbose_level);
22static int pentomino_puzzle_compare_func(
void *vec,
void *a,
int b,
void *data_for_compare);
41 nb_eqns = nb_eqn1 + nb_eqn2;
43 cout <<
"nb_vars=" << nb_vars << endl;
44 cout <<
"nb_eqn1=" << nb_eqn1 << endl;
45 cout <<
"nb_eqn2=" << nb_eqn2 << endl;
46 cout <<
"nb_eqns=" << nb_eqns << endl;
52 D->
open(nb_eqns, nb_vars);
58 int f_write_tree =
FALSE;
59 const char *fname_tree =
"";
62 cout <<
"After solve, we found " << D->
_resultanz <<
" solutions" << endl;
65 int nb_sol, sol_length = 5;
75 nb_sol, sol_length, 0 );
77 for (l = 0; l < nb_sol; l++) {
89 fname.assign(
"solutions.csv");
94 cout <<
"Solution 8:" << endl;
98 cout <<
"Solution 10:" << endl;
102 cout <<
"Solution 90:" << endl;
106 cout <<
"Solution 94:" << endl;
110 cout <<
"Solution 163:" << endl;
119 const char *fname =
"pentomino_all.tex";
125 fp <<
"\\noindent" << endl;
126 for (l = 0; l < nb_sol; l++) {
129 cout <<
"Solution " << l <<
" : ";
132 cout <<
"\\\\" << endl;
136 cout <<
"\\\\" << endl;
139 for (u = 0; u < sol_length; u++) {
140 j = Sol[l * sol_length + u];
142 cout <<
"j=" << j <<
" h=" << h <<
" r=" << r <<
" t=" << t << endl;
157 L->
compute_orbits(nb_orbits, orbit, orbit_inv, orbit_first, orbit_len,
158 pentomino_puzzle_compute_image_function,
163 cout <<
"We found " << nb_orbits <<
" orbits \\\\" << endl;
168 const char *fname =
"pentomino_orbits.tex";
174 fp <<
"\\noindent" << endl;
175 for (o = 0; o < nb_orbits; o++) {
179 cout <<
"Representative of orbit " << o <<
" is solution " << i <<
" : ";
181 cout <<
"\\\\" << endl;
185 cout <<
"\\\\" << endl;
187 if (((o + 1) % 35) == 0) {
188 cout << endl <<
"\\clearpage" << endl << endl <<
"\\noindent" << endl;
195 int nb_orbits_without_I;
196 int *orbits_without_I;
198 nb_orbits_without_I = 0;
199 orbits_without_I =
NEW_int(nb_orbits);
200 for (o = 0; o < nb_orbits; o++) {
218 orbits_without_I[nb_orbits_without_I++] = o;
221 cout <<
"We found " << nb_orbits_without_I <<
" orbits without I and with no interlocking L's and P's\\\\" << endl;
226 const char *fname =
"pentomino_orbits_reduced.tex";
233 fp <<
"\\noindent" << endl;
234 for (p = 0; p < nb_orbits_without_I; p++) {
235 o = orbits_without_I[p];
240 cout << p <<
" / " << nb_orbits_without_I <<
" Representative of orbit " << o <<
" is solution " << i <<
" : ";
242 cout <<
"\\\\" << endl;
246 cout <<
"\\\\" << endl;
248 if (((o + 1) % 35) == 0) {
249 cout << endl <<
"\\clearpage" << endl << endl <<
"\\noindent" << endl;
257 cout <<
"Orbits with interlocking Ps:\\\\" << endl;
259 for (p = 0; p < nb_orbits_without_I; p++) {
260 o = orbits_without_I[p];
265 cout <<
"With interlocking P's, orbit " << o <<
" without I is solution " << i <<
" : ";
266 int_vec_print(cout, L->
Sets[i], sol_length);
267 cout <<
"\\\\" << endl;
270 cout <<
"\\\\" << endl;
287 for (i = 0; i < 5; i++) {
296 for (i = 0; i < nb_L; i++) {
297 for (j = i + 1; j < nb_L; j++) {
312 for (i = 0; i < 5; i++) {
321 for (i = 0; i < nb_L; i++) {
322 for (j = i + 1; j < nb_L; j++) {
337 for (i = 0; i < 5; i++) {
346 for (i = 0; i < nb_L; i++) {
347 for (j = i + 1; j < nb_L; j++) {
362 for (i = 0; i < 5; i++) {
371 for (i = 0; i < nb_L; i++) {
372 for (j = i + 1; j < nb_L; j++) {
383 int h1 = 0, r1 = 0, t1 = 0, tt1, x1, y1, rr1;
384 int h2 = 0, r2 = 0, t2 = 0, tt2, x2, y2, rr2;
397 if (((rr1 + 2) % 4) != rr2) {
414 int h1 = 0, r1 = 0, t1 = 0, tt1, x1, y1, rr1;
415 int h2 = 0, r2 = 0, t2 = 0, tt2, x2, y2, rr2;
428 if (((rr1 + 2) % 4) != rr2) {
447 for (i = 0; i < 5; i++) {
460 for (i = 0; i < 5; i++) {
472 int i, h = 0, r = 0, t = 0, tt, x, y, rr;
478 for (i = 0; i < 5; i++) {
484 cout <<
"h=" << h <<
" r=" << r <<
" t=" << t
486 <<
" x=" << x <<
" y=" << y <<
" rr=" << rr << endl;
527 int u, h = 0, r = 0, rr, t = 0, tt, tx, ty, s, a, b, x, y, j;
530 ost <<
"\\begin{tikzpicture}[x=1cm, y=1cm, semitransparent, scale=0.5]" << endl;
531 ost <<
"\\draw[step=1cm, line width=0.3mm, black!30!white] (0,0) grid (5cm,5cm);" << endl;
532 for (u = 0; u < sol_length; u++) {
549 ost <<
"\\draw [very thick] ";
554 ost <<
"(" << x <<
"," << y <<
")";
562 ost <<
"\\end{tikzpicture}" << endl;
567 int gen_idx,
int &idx_of_image,
int verbose_level)
571 int f_v = (verbose_level >= 1);
572 int f_vv = (verbose_level >= 2);
575 int sz, i, a, b, h, r, t, idx;
578 set1 =
S->Sets[elt_idx];
579 sz =
S->Set_size[elt_idx];
584 cout <<
"compute_image_function "
585 "computing image of solution " << elt_idx <<
" = ";
587 cout <<
" under generator " << gen_idx << endl;
590 for (i = 0; i < sz; i++) {
594 cout <<
"a=" << a <<
" h=" << h <<
" r=" << r <<
" t=" << t <<
" -> ";
599 else if (gen_idx == 1) {
603 cout <<
"compute_image_function gen_idx unrecognized" << endl;
608 cout <<
"b=" << b <<
" h=" << h
609 <<
" r=" << r <<
" t=" << t << endl;
615 pentomino_puzzle_compare_func,
617 S->nb_sets, set2, idx, 0 )) {
618 cout <<
"compute_image_function cannot find image" << endl;
625 cout <<
"compute_image_function image is ";
627 cout <<
" which is solution " << idx_of_image << endl;
635 int tx, ty, txx = 0, tyy = 0, tt;
647 else if (h == 3 && r == 1) {
651 else if (h == 12 && r == 1) {
655 else if (h == 17 && r == 1) {
663 cout <<
"turn_piece cannot find "
664 "tt=" << tt <<
" for h=" << h << endl;
672 int f_v = (verbose_level >= 1);
673 int tx, ty, txx = 0, tyy = 0, tt;
677 cout <<
"flip_piece" << endl;
685 cout <<
"r=" << r <<
" tt=" << tt <<
" x=" << tx <<
" y=" << ty << endl;
691 else if (h == 3 && r == 0) {
695 else if (h == 7 || h == 8) {
705 else if (h == 9 || h == 10) {
721 else if (h == 12 || h == 17) {
737 else if (h == 11 || h == 16) {
753 else if (h == 4 || h == 13) {
769 else if (h == 5 || h == 14) {
785 else if (h == 6 || h == 15) {
801 else if (h == 1 || h == 2) {
819 cout <<
"r=" << r <<
" x'=" << txx <<
" y'=" << tyy <<
" tt=" << tt << endl;
822 cout <<
"flip_piece cannot find tt=" << tt <<
" for h=" << h << endl;
826 cout <<
"h'=" << h <<
" r'=" << r <<
" t'=" << t << endl;
829 cout <<
"flip_piece done" << endl;
837 int S1[] = {1,5,6,7,11,-1};
838 int S2[] = {1,2,5,6,11,-1};
839 int S3[] = {0,1,6,7,11,-1};
840 int S4[] = {0,5,10,15,20,-1};
841 int S5[] = {0,5,10,15,16,-1};
842 int S6[] = {1,6,10,11,15,-1};
843 int S7[] = {0,1,5,6,10,-1};
844 int S8[] = {0,1,2,6,11,-1};
845 int S9[] = {0,2,5,6,7,-1};
846 int S10[] = {0,5,10,11,12,-1};
847 int S11[] = {0,5,6,11,12,-1};
848 int S12[] = {1,5,6,11,16,-1};
849 int S13[] = {0,1,6,11,12,-1};
850 int S14[] = {1,6,11,15,16,-1};
851 int S15[] = {0,5,10,11,16,-1};
852 int S16[] = {0,1,5,6,11,-1};
853 int S17[] = {0,5,6,10,15,-1};
854 int S18[] = {1,2,6,10,11,-1};
857 int O1[] = {1,2,8,9,15,14,20,19,13,12,6,7,1,-1};
858 int O2[] = {1,3,9,8,20,19,13,12,6,7,1,-1};
859 int O3[] = {0,2,8,9,15,14,20,19,7,6,0,-1};
860 int O4[] = {0,1,31,30,0,-1};
861 int O5[] = {0,1,19,20,26,24,0,-1};
862 int O6[] = {1,2,20,19,25,24,12,13,1,-1};
863 int O7[] = {0,2,14,13,19,18,0,-1};
864 int O8[] = {0,3,9,8,20,19,7,6,0,-1};
865 int O9[] = {0,1,7,8,2,3,15,12,0,-1};
866 int O10[] = {0,1,13,15,21,18,0,-1};
867 int O11[] = {0,1,7,8,14,15,21,19,13,12,0,-1};
868 int O12[] = {1,2,26,25,13,12,6,7,1,-1};
869 int O13[] = {0,2,14,15,21,19,7,6,0,-1};
870 int O14[] = {1,2,26,24,18,19,1,-1};
871 int O15[] = {0,1,13,14,26,25,19,18,0,-1};
872 int O16[] = {0,2,20,19,13,12,0,-1};
873 int O17[] = {0,1,7,8,14,13,25,24,0,-1};
874 int O18[] = {1,3,9,8,20,18,12,13,1,-1};
878 int T1[] = {0,1,2,5,6,7,10,11,12,-1};
879 int T2[] = {0,1,2,5,6,7,10,11,12,-1};
880 int T3[] = {0,1,2,5,6,7,10,11,12,-1};
881 int T4[] = {0,1,2,3,4,-1};
882 int T5[] = {0,1,2,3,5,6,7,8,-1};
883 int T6[] = {0,1,2,3,5,6,7,8,-1};
884 int T7[] = {0,1,2,3,5,6,7,8,10,11,12,13,-1};
885 int T8[] = {0,1,2,5,6,7,10,11,12,-1};
886 int T9[] = {0,1,2,5,6,7,10,11,12,15,16,17,-1};
887 int T10[] = {0,1,2,5,6,7,10,11,12,-1};
888 int T11[] = {0,1,2,5,6,7,10,11,12,-1};
889 int T12[] = {0,1,2,3,5,6,7,8,-1};
890 int T13[] = {0,1,2,5,6,7,10,11,12,-1};
891 int T14[] = {0,1,2,3,5,6,7,8,-1};
892 int T15[] = {0,1,2,3,5,6,7,8,-1};
893 int T16[] = {0,1,2,3,5,6,7,8,10,11,12,13,-1};
894 int T17[] = {0,1,2,3,5,6,7,8,-1};
895 int T18[] = {0,1,2,5,6,7,10,11,12,-1};
899 int R2[] = {0,1,2,3,-1};
900 int R3[] = {0,1,2,3,-1};
902 int R5[] = {0,1,2,3,-1};
903 int R6[] = {0,1,2,3,-1};
904 int R7[] = {0,1,2,3,-1};
905 int R8[] = {0,1,2,3,-1};
906 int R9[] = {0,1,2,3,-1};
907 int R10[] = {0,1,2,3,-1};
908 int R11[] = {0,1,2,3,-1};
909 int R12[] = {0,1,2,3,-1};
910 int R13[] = {0,1,-1};
911 int R14[] = {0,1,2,3,-1};
912 int R15[] = {0,1,2,3,-1};
913 int R16[] = {0,1,2,3,-1};
914 int R17[] = {0,1,2,3,-1};
915 int R18[] = {0,1,-1};
1003 for (j = 0; ; j++) {
1004 if (
O[i][j] == -1) {
1009 for (j = 0; ; j++) {
1010 if (
T[i][j] == -1) {
1015 for (j = 0; ; j++) {
1016 if (
R[i][j] == -1) {
1026 int i, j, ii, jj, h;
1028 for (i = 0; i < 5; i++) {
1029 for (j = 0; j < 5; j++) {
1030 Rotate[0 * 25 + i * 5 + j] = i * 5 + j;
1033 for (i = 0; i < 5; i++) {
1035 for (j = 0; j < 5; j++) {
1037 Rotate[1 * 25 + i * 5 + j] = ii * 5 + jj;
1040 for (i = 0; i < 25; i++) {
1043 for (i = 0; i < 25; i++) {
1047 cout <<
"Rotate:" << endl;
1048 for (h = 0; h < 4; h++) {
1049 for (j = 0; j < 25; j++) {
1050 cout << setw(3) <<
Rotate[h * 25 + j] <<
" ";
1056 for (i = 0; i < 6; i++) {
1057 for (j = 0; j < 6; j++) {
1058 Rotate6[0 * 36 + i * 6 + j] = i * 6 + j;
1061 for (i = 0; i < 6; i++) {
1063 for (j = 0; j < 6; j++) {
1065 Rotate6[1 * 36 + i * 6 + j] = ii * 6 + jj;
1068 for (i = 0; i < 36; i++) {
1071 for (i = 0; i < 36; i++) {
1075 cout <<
"Rotate6:" << endl;
1076 for (h = 0; h < 4; h++) {
1077 for (j = 0; j < 36; j++) {
1078 cout << setw(3) <<
Rotate6[h * 36 + j] <<
" ";
1095 cout <<
"i : var_start[i] : var_length[i]" << endl;
1104 int i, h, j0, r, t, rr, tt, s, x, y, z;
1110 for (r = 0; r <
R_length[h]; r++) {
1113 for (t = 0; t <
T_length[h]; t++) {
1116 for (s = 0; s <
S_length[h]; s++) {
1131 for (h = 0; h < 6; h++) {
1134 for (r = 0; r <
R_length[h]; r++) {
1135 for (t = 0; t <
T_length[h]; t++) {
1136 D->
Aij(nb_eqn1 + h, j0 + r *
T_length[h] + t) = 1;
1143 for (i = 0; i < D->
m; i++) {
1152 void *compute_image_data,
int elt_idx,
1153 int gen_idx,
int &idx_of_image,
int verbose_level)
1158 gen_idx, idx_of_image, verbose_level);
1161static int pentomino_puzzle_compare_func(
void *vec,
void *a,
int b,
void *data_for_compare)
1172 int_vec_print(cout, (
int *) a, sz);
1174 int_vec_print(cout, S->
Sets[b], sz);
1175 cout <<
" yields " << c << endl;
generate all solutions of the pentomino puzzle
int code_piece(int h, int r, int t)
int has_interlocking_Lprime(long int *set)
void decode_assembly(long int *set)
void main(int verbose_level)
int var_start[NB_PIECES+1]
int has_interlocking_Pprime(long int *set)
int test_if_interlocking_Ls(int a1, int a2)
void compute_image_function(data_structures::set_of_sets *S, int elt_idx, int gen_idx, int &idx_of_image, int verbose_level)
void turn_piece(int &h, int &r, int &t, int verbose_level)
int var_length[NB_PIECES+1]
int has_interlocking_Ls(long int *set)
void decode_piece(int j, int &h, int &r, int &t)
void draw_it(std::ostream &ost, long int *sol)
void flip_piece(int &h, int &r, int &t, int verbose_level)
void make_coefficient_matrix(solvers::diophant *D)
int has_interlocking_Ps(long int *set)
int number_of_pieces_of_type(int t, long int *set)
int test_if_interlocking_Ps(int a1, int a2)
int does_it_contain_an_I(long int *set)
void sort_all(int verbose_level)
void sort_big(int verbose_level)
void compute_orbits(int &nb_orbits, int *&orbit, int *&orbit_inv, int *&orbit_first, int *&orbit_len, void(*compute_image_function)(set_of_sets *S, void *compute_image_data, int elt_idx, int gen_idx, int &idx_of_image, int verbose_level), void *compute_image_data, int nb_gens, int verbose_level)
void init_basic_constant_size(int underlying_set_size, int nb_sets, int constant_size, int verbose_level)
void save_csv(std::string &fname, int f_make_heading, int verbose_level)
a collection of functions related to sorted vectors
int vec_search_general(void *vec, int(*compare_func)(void *vec, void *a, int b, void *data_for_compare), void *data_for_compare, int len, void *a, int &idx, int verbose_level)
int lint_vec_compare(long int *p, long int *q, int len)
int int_vec_search_linear(int *v, int len, int a, int &idx)
void lint_vec_heapsort(long int *v, int len)
interface to create latex output files
void head_easy(std::ostream &ost)
void foot(std::ostream &ost)
diophantine systems of equations (i.e., linear systems over the integers)
void get_solutions(long int *&Sol, int &nb_sol, int verbose_level)
void fill_coefficient_matrix_with(int a)
int solve_all_DLX_with_RHS(int f_write_tree, const char *fname_tree, int verbose_level)
#define Lint_vec_copy(A, B, C)
#define Lint_vec_print(A, B, C)
the orbiter library for the classification of combinatorial objects