-
Notifications
You must be signed in to change notification settings - Fork 0
/
go_17sol_commands_cpp.h
872 lines (821 loc) · 28.7 KB
/
go_17sol_commands_cpp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
//========================================
const char * zh_g_cpt[10] = { "npuz", "guess", "close_d ", "upd1 ", "upd2 ",
"fupd ", "hpair ", "htripl ", " ", " " };
const char * libs_c17_00_cpt2g[40] = {
"0 bands1+2 processed entries M10",//0
"1 total bands 3",//1
"2 3X3Y entries",//2
"3 somme nx*ny",//3
"4 XY raw count/100 ",//4
"5 clean entries ",//5
"6 calls brute force ",//6
"7 valid brute force",//7
"8 setup mincount",//8
"9 minplus",//9
"10 go band3 all",//10
"11 b3 matrix",//11
"12 b3 nmiss0",//12
"13 b3 nmiss1",//13
"14 b3 nmiss2",//14
"15 b3 nmiss3",//15
"16 b2 minplus 5",//16
"17 ",//17
"18 n uas at start",//18
"19 n gua2s at start ",//19
"20 n gua3s at start ",//20
"21 ",//21
"22 ",//22
"23 max bands 3",//23
"24 ",//24
"25 <=128",
"26 <=256",
"27 entry crit",
"28 need to assign",
"29 ",
"30 ",
"31 ajouts uas",
"32 compte moins de 5 bandes",
"33 min 2_4",
"34 min 1_3",
"35 maxnuar",
"36 s4 <=128",
"37 s4<256",
"38 s4=256",
"39 compte ip",
};
void Go_c17_00( ) {// p2 process
cout << "Go_c17_00 search batch 17 clues 656 566 " << endl;
cout << sgo.vx[0] << " -v0- band 0_415" << endl;
cout << sgo.vx[2] << " -v2- skip first nnn restart after batch failure" << endl;
cout << sgo.vx[3] << " -v3- last entry number for this batch must be > vx[2]" << endl;
cout << sgo.vx[4] << " -v4- 0 if p2a 1 if p2b" << endl;
if(sgo.vx[5])cout << sgo.vx[5] << " -v5- band filter" << endl;
if (sgo.vx[6])cout << sgo.vx[6] << " -v6- diag option" << endl;
int it16_start = sgo.vx[0];
g17b.debug17 = g17b.debug17_check = g17b.aigstop=0;
//g17b.diag = sgo.vx[6];
genb12.skip = sgo.vx[2];
genb12.last = sgo.vx[3];
if (sgo.vx[2] < 0) {
cerr << "invalid value for skip" << endl;
return;
}
if (sgo.vx[3] < sgo.vx[2]) {
cerr << "invalid value for last to process" << endl;
return;
}
zh_g.modevalid = 1;
zh_g2.grid0 = genb12.grid0;
zh_g2.zsol = zh_g2.stdfirstsol;
memset(p_cptg, 0, sizeof p_cptg);// used in debugging sequences only
memset(p_cpt1g, 0, sizeof p_cpt1g);// used in debugging sequences only
memset(p_cpt2g, 0, sizeof p_cpt2g);// used in debugging sequences only
genb12.Start(0);
genb12.NewBand1(sgo.vx[0]);
cout << "print final stats" << endl;
for (int i = 0; i < 40; i++) {
if (!p_cpt2g[i])continue;
cout << p_cpt2g[i] << "\t\t" << libs_c17_00_cpt2g[i] << endl;
}
cout << "exit final stats" << endl;
}
void Go_c17_09() {// p2 process locate
cout << "Go_c17_09 search locate batch 17 clues 656 566 " << endl;
cout << sgo.vx[0] << " -v0- band 0_415" << endl;
cout << sgo.vx[2] << " -v2- skip first nnn restart after batch failure" << endl;
cout << sgo.vx[3] << " -v3- last entry number for this batch must be > vx[2]" << endl;
cout << sgo.vx[4] << " -v4- 0 if p2a 1 if p2b" << endl;
if (!sgo.vx[6] || !sgo.vx[7]) sgo.vx[6] = sgo.vx[7] = 0;
cout << sgo.vx[6] << " -v6- band2 searched" << endl;
cout << sgo.vx[7] << " -v7- band3 searched" << endl;
if (!sgo.vx[6] || !sgo.vx[7]) sgo.vx[6] = sgo.vx[7] = 0;
int it16_start = sgo.vx[0];
g17b.debug17 = g17b.debug17_check=0;
g17b.diag = sgo.vx[6];
genb12.skip = sgo.vx[2];
genb12.last = sgo.vx[3];
if (sgo.vx[2] < 0) {
cerr << "invalid value for skip" << endl;
return;
}
if (sgo.vx[3] < sgo.vx[2]) {
cerr << "invalid value for last to process" << endl;
return;
}
zh_g.modevalid = 1;
zh_g2.grid0 = genb12.grid0;
zh_g2.zsol = zh_g2.stdfirstsol;
memset(p_cpt2g, 0, sizeof p_cpt2g);// used in debugging sequences only
genb12.Start(0);
genb12.NewBand1(sgo.vx[0]);
}
//========================= known s17 file 10/19
void Go_c17_10( ) {
zh_g.modevalid = 1;
zh_g2.grid0 = genb12.grid0;
zh_g2.zsol = zh_g2.stdfirstsol;
// search 17 using a file having known as entry and one 17 given 6 6 5
char * ze = finput.ze;
int * zs0 = genb12.grid0, npuz = 0;
cout << "Go_c17_10() search 17 using a file having known 17 656 " << endl;
while (finput.GetLigne()) {
if(strlen(ze)<160) continue;// skip blank lines
npuz++;
g17b.npuz = npuz;
g17b.a_17_found_here = 0;
g17b.aigstop= 0;
if (npuz <= (int)sgo.vx[2]) continue;
if (npuz > (int)sgo.vx[3]) break;
g17b.debug17 = sgo.vx[0];
g17b.debug17_check = 0;
//if (npuz >5) return;
cout << "\n\nto process n="<<dec << npuz <<" debug="<< g17b.debug17 << endl;
long tdeb = GetTimeMillis();
//================================ to avoid the 665 case
int ncb3 = 0;
for (int i = 0; i < 27; i++)
if (ze[i + 136] - '.')ncb3++;
if (ncb3 == 5) {// change band3 <-> band2
for (int i = 0; i < 27; i++) {
char temp = ze[i + 27]; ze[i + 27] = ze[i + 54]; ze[i + 54] = temp;
temp = ze[i + 109]; ze[i + 109] = ze[i + 136]; ze[i + 136] = temp;
}
}
if (g17b.debug17)
cout << ze << " to process n=" << npuz << endl;
// =======================morph entry
for (int i = 0; i < 81; i++)zs0[i] = ze[i] - '1';
BANDMINLEX::PERM perm_ret;
bandminlex.Getmin(zs0, &perm_ret);
int ib1 = perm_ret.i416, ib1a = t416_to_n6[ib1];
myband1.InitBand2_3(ib1, ze, perm_ret, 0);
bandminlex.Getmin(&zs0[27], &perm_ret);
int ib2 = perm_ret.i416, ib2a = t416_to_n6[ib2];
myband2.InitBand2_3(ib2, &ze[27], perm_ret, 1);
bandminlex.Getmin(&zs0[54], &perm_ret);
int ib3 = perm_ret.i416, ib3a = t416_to_n6[ib3];
genb12.bands3[0].InitBand3(ib3, &ze[54], perm_ret);
genb12.nband3 = 1;
tulock.InitBuf();
myband1.ExpandBand();// expand band1
tulock.LockExpand(myband1.nmyi3, myband1.nmybv5, myband1.nmybv6);
tulock.Store1();
ze[81] = 0;
char * ze2 = &ze[82];
g17b.p17diag.SetAll_0();
for (int i = 0; i < 81; i++) if (ze2[i] != '.')
g17b.p17diag.Set_c(i);
if (g17b.debug17)
cout << Char2Xout(g17b.p17diag.bf.u64[0]) << " b12 pattern for the 17" << endl;
genb12.ValidInitGang();
g17b.npuz = npuz;
g17b.GoM10();
//g17b.a_17_found_here = 1;
if (!g17b.a_17_found_here) {
cout << "puz="<<npuz << " failed to find the searched 17" << endl;
cerr << "puz=" << npuz << " failed to find the searched 17" << endl;
break;
}
}
cout << "print final stats" << endl;
for (int i = 0; i < 40; i++) {
if (!p_cpt2g[i])continue;
cout << p_cpt2g[i] << "\t\t" << libs_c17_00_cpt2g[i] << endl;
}
}
void Go_c17_11() {// extract cout xx5 file1 xx6
// search 17 using a file having known as entry and one 17 given 6 6 5
char * ze = finput.ze;
int * zs0 = genb12.grid0, npuz = 0;
cout << "Go_c17_11() split known 17 b3_5 b3_6 " << endl;
while (finput.GetLigne()) {
// =======================morph entry to have min n6 count in first
for (int i = 0; i < 81; i++)zs0[i] = ze[i] - '1';
BANDMINLEX::PERM perm_ret;
bandminlex.Getmin(zs0, &perm_ret);
int ib1 = perm_ret.i416, ib1a = t416_to_n6[ib1];
bandminlex.Getmin(&zs0[27], &perm_ret);
int ib2 = perm_ret.i416, ib2a = t416_to_n6[ib2];
bandminlex.Getmin(&zs0[54], &perm_ret);
int ib3 = perm_ret.i416, ib3a = t416_to_n6[ib3];
if (ib1a > ib2a) {// change band2 <-> band1
for (int i = 0; i < 27; i++) {
char temp = ze[i]; ze[i] = ze[i + 27]; ze[i + 27] = temp;
temp = ze[i + 82]; ze[i + 82] = ze[i + 109]; ze[i + 109] = temp;
int w = ib1a; ib1a = ib2a; ib2a = w;
}
}
if (ib1a > ib3a) {// change band3 <-> band1
for (int i = 0; i < 27; i++) {
char temp = ze[i]; ze[i] = ze[i + 54]; ze[i + 54] = temp;
temp = ze[i + 82]; ze[i + 82] = ze[i + 136]; ze[i + 136] = temp;
int w = ib1a; ib1a = ib3a; ib3a = w;
}
}
int ncb3 = 0;
for (int i = 0; i < 27; i++) {
if (ze[i + 136] - '.')ncb3++;
}
if (ncb3 == 6) {
fout1 <<&ze[82] << ";" << ib2a
<< ";" << ib3a <<endl;
continue;
}
// now 5 clues in band 3 exchange bands
for (int i = 0; i < 27; i++) {
char temp = ze[i + 27]; ze[i + 27] = ze[i + 54]; ze[i + 54] = temp;
temp = ze[i + 109]; ze[i + 109] = ze[i + 136]; ze[i + 136] = temp;
}
int w = ib2a; ib2a = ib3a; ib3a = w;
cout << &ze[82] << ";" << ib2a
<< ";" << ib3a << endl;
}
}
//=========================== regressive tests
void Go_c17_91_go() {
if (p_cptg[0] > 1) return;
myband1.PrintStatus();
myband2.PrintStatus();
genuasb12.Initgen();
}
void Go_c17_80() {// enumeration test
cout << "Go_c17_20 phase 2a enumeration test " << endl;
cout << sgo.vx[0] << " -v0- first id 0_415" << endl;
cout << sgo.vx[1] << " -v1- second id 0_415" << endl;
cout << sgo.vx[2] << " -v2- if 1 printout asked" << endl;
cout << sgo.vx[4] << " -v4- 0 mode p2a 1 mode p2b 2 mode p1" << endl;
int it16_start = sgo.vx[0], it16_end = sgo.vx[1];
genb12.skip = 0;
genb12.last = 100000;
if (it16_start > 415 || it16_end > 415 || it16_start > it16_end) {
cerr << "invalid it16_start it16_end" << endl;
return;
}
memset(p_cptg, 0, sizeof p_cptg);// used in debugging sequences only
genb12.Start(11);// mode p2a or p2b or p1
for (int i1t16 = it16_start; i1t16 <= it16_end; i1t16++) {
memset(p_cpt, 0, sizeof p_cpt);// band2 and band 3 count
genb12.nb12 = 0;
genb12.NewBand1(i1t16);
cout << genb12.i1t16 << "\t" << genb12.it16 << "\t" << p_cpt[0]
<< "\t" << p_cpt[1] << endl;
p_cptg[0] += p_cpt[0];
p_cptg[1] += p_cpt[1];
}
cout << "total\t\t" << p_cptg[0]
<< "\t" << p_cptg[1] << endl;
}
void Go_c17_90() {// creating band UAs
//the table exists, this is somehow a regressive test
//or to rebuild the table
cout << "Go_10 entry creating band uas test" << endl;
STD_B416 wband;
wband.Initstd();
int maxua = 0;
zh1b_g.diag = 0;
for (int i416 = 0; i416 < 416; i416++) {
//for (int i416 = 64; i416 <= 64; i416++) {
wband.InitC10(i416);
int nua = t16_nua[i416]; // reference known
zhone[0].InitOne_std_band();
cout << wband.band << " i416=" << i416 << endl;
for (int i = 0; i < 36; i++) {// find UAs 2 digits
if (zhone[0].Start_nFloors(floors_2d[i])) continue;
zhone[0].InitGuess();
zhone[0].Guess2();
}
for (int i = 0; i < 84; i++) {// find UAs 3 digits
if (zhone[0].Start_nFloors(floors_3d[i])) continue;
zhone[0].InitGuess();
zhone[0].Guess3();
}
if (t16_nua[i416] == zh1b_g.nua)goto ok;
for (int i = 0; i < 126; i++) {// find UAs 4 digits
if (zhone[0].Start_nFloors(floors_4d[i])) continue;
zhone[0].InitGuess();
zhone[0].Guess4();
}
for (int i = 0; i < 126; i++) {// find UAs 5 digits
if (zhone[0].Start_nFloors(0x1ff ^ floors_4d[i])) continue;
zhone[0].InitGuess();
if (0 && floors_4d[i] == 0113) {
zhone[0].ImageCandidats();
zh1b_g.diag = 1;
}
else zh1b_g.diag = 0;
zhone[0].Guess5();
}
for (int i = 0; i < 84; i++) {// find UAs 6 digits
if (zhone[0].Start_nFloors(0x1ff ^ floors_3d[i])) continue;
zhone[0].InitGuess();
zhone[0].Guess6();
}
if (t16_nua[i416] == zh1b_g.nua)goto ok;
//if(1)zh1b_g.PrintTua();
zh1b_g.FindMissingUAs();
if (t16_nua[i416] == zh1b_g.nua)goto ok;
{
cout << "uas final table" << endl;
zh1b_g.PrintTua();
cout << "uas known table" << endl;
int id = t16_indua[i416], iff = id + t16_nua[i416];
for (int i = id; i < iff; i++)
cout << i - id << "\t"
<< Char27out(t16_UAs[i]) << "\t" << _popcnt32(t16_UAs[i]) << endl;
continue;
}
ok:
cout << "ua count equal" << endl;
}
}
void Go_c17_91() {// UAs collector 2 bands
cout << "Go_11 test UAs collector 2 ba,ds" << endl;
cout << sgo.vx[0] << " -v0- id bande low order 0_415" << endl;
cout << sgo.vx[0] << " -v1- number of band2" << endl;
memset(p_cpt, 0, sizeof p_cpt);// used in debugging sequences only
memset(p_cpt1, 0, sizeof p_cpt1);// used in debugging sequences only
genb12.Start(10);
genb12.NewBand1(sgo.vx[0]);
}
/* sample used for Go_c17_92()
1 0 0 0 0 0 729 18225
28 27 0 38 2025 26285 157845 610977
29 28 9 567 7398 51516 237762 803574
412 411 0 0 0 324 10503 112491
413 412 0 0 0 0 729 18225
32 31 0 0 0 546 12291 101597
*/
void Go_c17_92() {// test UAs 5 6 expand
cout << "entry 92" << endl;
tulock.InitBuf();
uint32_t cpt[10];
memset(cpt, 0, sizeof cpt);// used in debugging sequences only
for (int it16 = 0; it16 <= 415; it16++) {
myband1.Initstd();
myband1.InitG12(it16);
myband1.ExpandBand();// expand and set index
//cout << "it16=" << it16 << endl;
//myband1.DebugIndex();
//break;
if (myband1.nmyi3 >(int) cpt[0])cpt[0] = myband1.nmyi3;
if (myband1.nmybv5 >(int) cpt[1])cpt[1] = myband1.nmybv5;
if (myband1.nmybv6 > (int)cpt[2])cpt[2] = myband1.nmybv6;
for (int i = 0; i < myband1.nmyi3-1; i++) {
XINDEX3 x1 = myband1.myi3[i], x2 = myband1.myi3[i + 1];
uint32_t n5 = x2.ideb5 - x1.ideb5,
n6 = x2.ideb - x1.ideb;
if (n5 > cpt[3])cpt[3] = n5;
if (n6 > cpt[4])cpt[4] = n6;
}
}
cout << "maxindex=" << cpt[0] << endl;
cout << "maxn5=" << cpt[1] << endl;
cout << "maxn6=" << cpt[2] << endl;
cout << "maxdet5=" << cpt[3] << endl;
cout << "maxdet6=" << cpt[4] << endl;
}
//====== 15 extraction des 17 6 6 5
void Go_c17_15() {
char * ze = finput.ze;
while (finput.GetLigne()) {
int count[6];
memset(count, 0, sizeof count);
for (int i = 0; i < 81; i++) {
if (ze[i] - '.') {
int band = i / 27, stack = C_stack[i] + 3;
++count[band];
++count[stack];
}
}
if (count[0] > 6 || count[1] > 6 ||
count[2] > 6 || count[3] > 6 ||
count[4] > 6 || count[5] > 6)
cout << ze << endl;
else fout1 << ze << endl;
}
}
void Msp_ReorderBand(char * ze,char * zep=0)
{
char temp[9];
if (ze[0] > ze[9]) {
memmove(temp, ze, sizeof temp);
memmove(ze, &ze[9], sizeof temp);
memmove(&ze[9], temp,sizeof temp);
if (zep) {
memmove(temp, zep, sizeof temp);
memmove(zep, &zep[9], sizeof temp);
memmove(&zep[9], temp, sizeof temp);
}
}
if (ze[0] > ze[18]) {
memmove(temp, ze, sizeof temp);
memmove(ze, &ze[18], sizeof temp);
memmove(&ze[18], temp, sizeof temp);
if (zep) {
memmove(temp, zep, sizeof temp);
memmove(zep, &zep[18], sizeof temp);
memmove(&zep[18], temp, sizeof temp);
}
}
if (ze[9] > ze[18]) {
memmove(temp, &ze[9], sizeof temp);
memmove(&ze[9], &ze[18], sizeof temp);
memmove(&ze[18], temp, sizeof temp);
if (zep) {
memmove(temp, &zep[9], sizeof temp);
memmove(&zep[9], &zep[18], sizeof temp);
memmove(&zep[18], temp, sizeof temp);
}
}
}
void Go_c17_16() {
char * ze = finput.ze,zout[82],zdiag[82],zew[82],zes[82], zesf[82];
zout[81] = zdiag[81] = zes[81] = 0;
zh_g2.zsol = zout;
while (finput.GetLigne()) {
if (zhou[0].CheckValidityQuick(ze) == 1) {
int count[6];
memset(count, 0, sizeof count);
for (int i = 0; i < 81; i++) {
if (ze[i] - '.') {
int band = i / 27, stack = C_stack[i] + 3;
++count[band];
++count[stack];
}
}
for (int i = 0; i < 81; i++)
zdiag[C_transpose_d[i]] = zout[i];
int zw[27], indexr[6], indexmin = 500;
BANDMINLEX::PERM pr;
char * zz = zout;
for (int i = 0; i < 27; i++)
zw[i] = zz[i] - '1';
bandminlex.Getmin(zw, &pr);
indexmin = indexr[0] = t416_to_n6[pr.i416];
zz = &zout[27];
for (int i = 0; i < 27; i++)
zw[i] = zz[i] - '1';
bandminlex.Getmin(zw, &pr);
indexr[1] = t416_to_n6[pr.i416];
if (indexmin > indexr[1])indexmin = indexr[1];
zz = &zout[54];
for (int i = 0; i < 27; i++)
zw[i] = zz[i] - '1';
bandminlex.Getmin(zw, &pr);
indexr[2] = t416_to_n6[pr.i416];
if (indexmin > indexr[2])indexmin = indexr[2];
zz = zdiag;
for (int i = 0; i < 27; i++)
zw[i] = zz[i] - '1';
bandminlex.Getmin(zw, &pr);
indexr[3] = t416_to_n6[pr.i416];
if (indexmin > indexr[3])indexmin = indexr[3];
zz = &zdiag[27];
for (int i = 0; i < 27; i++)
zw[i] = zz[i] - '1';
bandminlex.Getmin(zw, &pr);
indexr[4] = t416_to_n6[pr.i416];
if (indexmin > indexr[4])indexmin = indexr[4];
zz = &zdiag[54];
for (int i = 0; i < 27; i++)
zw[i] = zz[i] - '1';
bandminlex.Getmin(zw, &pr);
indexr[5] = t416_to_n6[pr.i416];
if (indexmin > indexr[5])indexmin = indexr[5];
// sort and keep track of the count or split the file
if (sgo.vx[6] && indexmin != sgo.vx[6]) continue;
uint32_t tx[3], tdx[3], temp;
tx[0] = (indexr[0] << 8) | count[0];
tx[1] = (indexr[1] << 8) | count[1]|010;
tx[2] = (indexr[2] << 8) | count[2]|020;
tdx[0] = (indexr[3] << 8) | count[3];
tdx[1] = (indexr[4] << 8) | count[4]|010;
tdx[2] = (indexr[5] << 8) | count[5]|020;
if (tx[0] > tx[1]) { temp = tx[0]; tx[0] = tx[1]; tx[1] = temp; }
if (tx[0] > tx[2]) { temp = tx[0]; tx[0] = tx[2]; tx[2] = temp; }
if (tx[1] > tx[2]) { temp = tx[1]; tx[1] = tx[2]; tx[2] = temp; }
if (tdx[0] > tdx[1]) { temp = tdx[0]; tdx[0] = tdx[1]; tdx[1] = temp; }
if (tdx[0] > tdx[2]) { temp = tdx[0]; tdx[0] = tdx[2]; tdx[2] = temp; }
if (tdx[1] > tdx[2]) { temp = tdx[1]; tdx[1] = tdx[2]; tdx[2] = temp; }
BF64 va, vb; va.bf.u64 = vb.bf.u64 = 0;
va.bf.u16[2] = tx[0] >> 8; va.bf.u16[1] = tx[1] >> 8; va.bf.u16[0] = tx[2] >> 8;
vb.bf.u16[2] = tdx[0] >> 8; vb.bf.u16[1] = tdx[1] >> 8; vb.bf.u16[0] = tdx[2] >> 8;
if (sgo.vx[6]) {// check bands 2 3 for test
cout << "va1=" << va.bf.u16[2] << " va2=" << va.bf.u16[1]
<< " va3=" << va.bf.u16[0] << "\tvb1=" << vb.bf.u16[2] << " vb2=" << vb.bf.u16[1]
<< " vb3=" << vb.bf.u16[0];
if (va.bf.u64 <= vb.bf.u64) cout << "\tdirect"<<endl;
else {
cout << "\tdiag"<<endl;
}
}
strcpy(zew, ze);// to morph the expected 17 puzzle
if (va.bf.u64 > vb.bf.u64) {
va = vb;
memcpy(tx, tdx, sizeof tx);
strcpy(zout, zdiag);
for (int i = 0; i < 81; i++)zew[C_transpose_d[i]] = ze[i];
}
if (sgo.vx[6]) {// check bands 2 3 for test
if (va.bf.u16[2] != sgo.vx[6]) continue;
if (va.bf.u16[1] != sgo.vx[7]) continue;
}
char zs[82], zsa[82]; zsa[81] = zs[81] = 0;
int i1 = (tx[0] & 070) >> 3, i2 = (tx[1] & 070) >> 3, i3 = (tx[2] & 070) >> 3;
memcpy(zsa, &zout[27 * i1], 27);
memcpy(&zsa[27], &zout[27 * i2], 27);
memcpy(&zsa[54], &zout[27 * i3], 27);
memcpy(zes, &zew[27 * i1], 27);
memcpy(&zes[27], &zew[27 * i2], 27);
memcpy(&zes[54], &zew[27 * i3], 27);
int zs0[81];
// redo id to build tables
int ib1, ib1a, ib2, ib2a, ib3, ib3a;
for (int i = 0; i < 81; i++)zs0[i] = zsa[i] - '1';
BANDMINLEX::PERM pb1, prw;
bandminlex.Getmin(zs0, &pb1);
ib1 = pb1.i416;
ib1a = t416_to_n6[ib1];
//myband1.InitBand2_3(ib1, zsa, perm_ret, 0);
bandminlex.Getmin(&zs0[27], &prw);
ib2 = prw.i416;
ib2a = t416_to_n6[ib2];
//myband2.InitBand2_3(ib2, &zsa[27], perm_ret, 1);
bandminlex.Getmin(&zs0[54], &prw);
ib3 = prw.i416;
ib3a = t416_to_n6[ib3];
strcpy(zs, "12345678945");
strncpy(&zs[11], t416[ib1], 16);
strcpy(zesf, empty_puzzle);
// relabel all
for (int i = 3, ij = 27; i < 9; i++)
for (int j = 0; j < 9; j++, ij++) {
int is = 9 * i + pb1.cols[j];
int c = zsa[is] - '1';
zs[ij] = pb1.map[c] + '1';
if (zes[is] != '.')zesf[ij] = zs[ij];
}
if (sgo.vx[6]) {
cout << "\ti1,2,3 " << i1 << i2 << i3 << endl;
cout << ze << " ze" << endl;
cout << zes << " zes" << endl;
cout << zout << endl;
cout << zsa << endl;
//genb12.bands3[0].InitBand3(ib3, &zsa[54], perm_ret);
}
Msp_ReorderBand(&zs[27], &zesf[27]);
Msp_ReorderBand(&zs[54], &zesf[54]);
// reorder band1 p17
for (int i = 0, ij = 0; i < 3; i++)
for (int j = 0; j < 9; j++, ij++) {
int is = 9 * pb1.rows[i] + pb1.cols[j],
c = zes[is];
if (c != '.')zesf[ij] = zs[ij];
}
if (sgo.vx[6]) {
cout << "ib1a=" << ib1a << " ib2a=" << ib2a << " ib3a=" << ib3a << endl;
cout << zs << "zsa morphed relabeled" << endl;
cout << zs << "zsa reordered" << endl;
cout << zesf << "zes reordered relabelled" << endl;
}
fout1 << zs << ";" << zesf << ";" << indexmin << ";";
fout1 << va.bf.u16[1] << ";"
<< va.bf.u16[0] << ";" << (tx[2] & 07) << endl;
}
else cout << ze << "non resolu" << endl;
}
}
/*
void GEN_BANDES_12::Morph_ED_B12_known17(char * z, int ib1){
i1t16 = ib1; it16 = tn6_to_416[ib1];
char zw[164], *zb1p = &z[82], *zb2p = &z[27 + 82], *zb3p = &z[54 + 82];
strcpy(zw, z);
unsigned long g0[81], *z02 = &g0[27], *z03 = &g0[54],zcomp[27];
for (int i = 0; i < 81; i++)g0[i] = z[i] - '1';
__movsd(zcomp,z02,27);
n_auto_b1 = bandminlex.GetAutoMorphs(it16, t_auto_b1);
cout << "processing band rank=" << i1t16 << " N° 1_416=" << it16 + 1
<< " n auto morphs=" << n_auto_b1 << endl;
if (n_auto_b1){
for (int imorph = 0; imorph < n_auto_b1; imorph++){
BANDMINLEX::PERM &p = t_auto_b1[imorph];
unsigned long band[27];// morph the band
for (int i = 0; i < 9; i++){
band[i] = p.map[z02[p.cols[i]]];
band[i + 9] = p.map[z02[p.cols[i] + 9]];
band[i + 18] = p.map[z02[p.cols[i] + 18]];
}
if( G17ComparedOrderedBand((int *)zcomp,(int *) band)==1){//morph to p orderd
int tsort[3];
G17BuildSort((int *)band, tsort);
cout << p.rows[0] << p.rows[1] << p.rows[2] << " rows"<<endl;
for (int i = 0; i < 3; i++){
int ir = tsort[i] &= 3,irb1=p.rows[i];
__movsd(&zcomp[9*i], &band[9 * ir], 9);// new zs0
for (int j = 0; j < 9; j++){// new entry
int wc = band[9 * ir + j]+ '1',wc2=wc;
if (zb2p[ 9 * ir + p.cols[j]] == '.') wc2 = '.';
zw[27 + 9 * i + j] = wc;
zw[27+82 + 9 * i + j] = wc2;
wc = p.map[z03[9 * i + p.cols[j]] ] + '1';
wc2 = wc;
if (zb3p[ 9 * i + p.cols[j]] == '.') wc2 = '.';
zw[54 + 9 * i + j] = wc;
zw[54 + 82 + 9 * i + j] = wc2;
wc2 = p.map[g0[9 * irb1 + p.cols[j]]] + '1';
if (z[82+9 * irb1 + p.cols[j]] == '.') wc2 = '.';
zw[82 + 9 * i + j] = wc2;
}
}
cout << zw << "après morph une etape" << endl;
}
}
}
cout << zw << "après morph ED band 12" << endl;
}
*/
void msp_change12(char * ze, int &ib1a, int & ib2a) {
for (int i = 0; i < 27; i++) {
char temp = ze[i]; ze[i] = ze[i + 27]; ze[i + 27] = temp;
temp = ze[i + 82]; ze[i + 82] = ze[i + 109]; ze[i + 109] = temp;
int w = ib1a; ib1a = ib2a; ib2a = w;
}
}
void msp_change13(char * ze, int &ib1a, int & ib3a) {
for (int i = 0; i < 27; i++) {
char temp = ze[i]; ze[i] = ze[i + 54]; ze[i + 54] = temp;
temp = ze[i + 82]; ze[i + 82] = ze[i + 136]; ze[i + 136] = temp;
int w = ib1a; ib1a = ib3a; ib3a = w;
}
}
void msp_change23(char * ze, int &ib2a, int & ib3a) {
msp_change12(&ze[27], ib2a, ib3a);
}
void M1_S17_Morph(char * z, BANDMINLEX::PERM & p1) {
char zw[164]; strcpy(zw, z); // pose 0 et ;
// map band 1
for (int ir = 0, i = 0; ir < 3; ir++)for (int ic = 0; ic < 9; ic++, i++) {
int iw = 9 * p1.rows[ir] + p1.cols[ic];
char cw1 = p1.map[z[iw] - '1'] + '1', cw2 = cw1;
if (z[iw + 82] == '.') cw2 = '.';
zw[i] = cw1; zw[i + 82] = cw2;
}
{// map band2 to band 1 reorder columns
int iw4 = 27 + p1.cols[0], iw5 = 36 + p1.cols[0], iw6 = 45 + p1.cols[0];
int cw4 = p1.map[z[iw4] - '1'], cw5 = p1.map[z[iw5] - '1'], cw6 = p1.map[z[iw6] - '1'];
int tsort[3], w;// sort bands / stacks increasing order of the id
tsort[0] = cw4 << 8;
tsort[1] = 1 | (cw5 << 8);
tsort[2] = 2 | (cw6 << 8);
for (int i = 0; i < 2; i++) for (int j = i + 1; j < 3; j++)
if (tsort[i] > tsort[j]) { w = tsort[i]; tsort[i] = tsort[j]; tsort[j] = w; }
tsort[0] &= 3; tsort[1] &= 3; tsort[2] &= 3;
for (int ir = 0, i = 27; ir < 3; ir++)for (int ic = 0; ic < 9; ic++, i++) {
int iw = 9 * tsort[ir] + p1.cols[ic] + 27;
char cw1 = p1.map[z[iw] - '1'] + '1', cw2 = cw1;
if (z[iw + 82] == '.') cw2 = '.';
zw[i] = cw1; zw[i + 82] = cw2;
}
}
{// map band3 to band 1 reorder columns
int iw5 = 54 + p1.cols[0], iw6 = 63 + p1.cols[0], iw7 = 72 + p1.cols[0];
int cw5 = p1.map[z[iw5] - '1'], cw6 = p1.map[z[iw6] - '1'], cw7 = p1.map[z[iw7] - '1'];
int tsort[3], w;// sort bands / stacks increasing order of the id
tsort[0] = cw5 << 8;
tsort[1] = 1 | (cw6 << 8);
tsort[2] = 2 | (cw7 << 8);
for (int i = 0; i < 2; i++) for (int j = i + 1; j < 3; j++)
if (tsort[i] > tsort[j]) { w = tsort[i]; tsort[i] = tsort[j]; tsort[j] = w; }
tsort[0] &= 3; tsort[1] &= 3; tsort[2] &= 3;
for (int ir = 0, i = 54; ir < 3; ir++)for (int ic = 0; ic < 9; ic++, i++) {
int iw = 9 * tsort[ir] + p1.cols[ic] + 54;
char cw1 = p1.map[z[iw] - '1'] + '1', cw2 = cw1;
if (z[iw + 82] == '.') cw2 = '.';
zw[i] = cw1; zw[i + 82] = cw2;
}
}
strcpy(z, zw);
//zw[54] = 0; zw[54 + 82] = 0;
//fout1 << zw << endl;
}
void M1_S17(char * finput_name, char * foutput_name, uint32_t * vx, uint32_t * bx) {
// temporary code extract solution with a known 17 6 6 5
finput.open(finput_name);
if (!finput.is_open()) { cerr << "error open file " << finput_name << endl; return; }
fout1.open(foutput_name);
char * ze = finput.ze, *ze2 = &ze[82];
char zdiag[164], zw[164];
zdiag[81] = ';'; zdiag[163] = 0;
int count[6], zwi[81], zei[81], zdiagi[81];
while (finput.GetLigne()) {
if (strlen(ze) < 163)continue;
ze[163] = 0; // forget more info
memset(count, 0, sizeof count);
for (int i = 0; i < 81; i++) {
if (ze2[i] - '.') {
int band = i / 27, stack = C_stack[i] + 3;
++count[band];
++count[stack];
}
zdiag[C_transpose_d[i]] = ze[i];
zdiag[C_transpose_d[i] + 82] = ze[i + 82];
}
BANDMINLEX::PERM pr[6];
for (int ib = 0; ib < 6; ib++)if (count[ib] > 6) {
if (0) goto next;
int x;
// morph the puzzle to the high band in band
if (ib > 2)memmove(zw, zdiag, sizeof zw);
else memmove(zw, ze, sizeof zw);
// put the >6 clues band as band3
if (ib == 0 || ib == 3) msp_change13(zw, x, x);
else if (ib == 1 || ib == 4) msp_change23(zw, x, x);
for (int i = 0; i < 54; i++) zwi[i] = zw[i] - '1';
bandminlex.Getmin(zwi, &pr[0]);
int ib1 = pr[0].i416, ib1a = t416_to_n6[ib1];
bandminlex.Getmin(&zwi[27], &pr[1]);
int ib2 = pr[1].i416, ib2a = t416_to_n6[ib2],
i2 = ib2a, i1 = ib1a;
if (ib1a > ib2a) {
msp_change12(zw, i1, i2);
M1_S17_Morph(zw, pr[1]);
}
else M1_S17_Morph(zw, pr[0]);
fout1 << zw << ";" << i1 << ";" << i2 << endl;
cout << zw << endl;
//genb12.Morph_ED_B12_known17(zw, i1);
if (0) {// mode look for 566 656 no 7 in stack
char zout[164];
for (int i = 0; i < 81; i++) {
zei[i] = ze[i] - '1';
zdiagi[i] = zdiag[i] - '1';
}
BANDMINLEX::PERM perm_reti[6];
int ibi[6], ibri[6];
for (int i = 0; i < 3; i++) {
bandminlex.Getmin(&zei[27 * i], &perm_reti[i]);
ibi[i] = perm_reti[i].i416;
ibri[i] = t416_to_n6[ibi[i]];
bandminlex.Getmin(&zdiagi[27 * i], &perm_reti[i + 3]);
ibi[i + 3] = perm_reti[i + 3].i416;
ibri[i + 3] = t416_to_n6[ibi[i + 3]];
}
int tsort[3], w;// sort bands / stacks increasing order of the id
tsort[0] = ibri[0] << 8;
tsort[1] = 1 | (ibri[1] << 8);
tsort[2] = 2 | (ibri[2] << 8);
for (int i = 0; i < 2; i++) for (int j = i + 1; j < 3; j++)
if (tsort[i] > tsort[j]) { w = tsort[i]; tsort[i] = tsort[j]; tsort[j] = w; }
int ib1 = tsort[0] & 3, ib2 = tsort[1] & 3, ib3 = tsort[2] & 3;
tsort[0] = 3 | ibri[3] << 8;
tsort[1] = 4 | (ibri[4] << 8);
tsort[2] = 5 | (ibri[5] << 8);
for (int i = 0; i < 2; i++) for (int j = i + 1; j < 3; j++)
if (tsort[i] > tsort[j]) { w = tsort[i]; tsort[i] = tsort[j]; tsort[j] = w; }
int ibd1 = tsort[0] & 3, ibd2 = tsort[1] & 3, ibd3 = tsort[2] & 3;
char *z = ze;
int * cpt = count, iout = ibri[ib1];
if (ibri[ib1] < ibri[ibd1]) goto bands;
if (ibri[ib1] > ibri[ibd1]) goto stacks;
if (ibri[ib2] < ibri[ibd2]) goto bands;
if (ibri[ib2] > ibri[ibd2]) goto stacks;
goto bands;// not a key point, use band
stacks:
z = zdiag;
cpt = &count[3];
ib1 = ibd1 - 3; ib2 = ibd2 - 3; ib3 = ibd3 - 3;
iout = ibri[ibd1];
bands: {
strcpy(zout, z);
if (ib1) {
memcpy(zout, &ze[27 * ib1], 27);
memcpy(&zout[82], &ze[27 * ib1 + 82], 27);
}
if (count[ib3] == 5) {// must be pass2b
if (ib3 != 2) {
memcpy(&zout[27], &z[27 * ib3], 27);
memcpy(&zout[82 + 27], &z[27 * ib3 + 82], 27);
}
if (ib2 != 3) {
memcpy(&zout[54], &z[27 * ib2], 27);
memcpy(&zout[82 + 54], &z[27 * ib2 + 82], 27);
}
fout1 << z << ";" << iout << endl;
}
else {// pass2a
if (ib2 != 2) {
memcpy(&zout[27], &z[27 * ib2], 27);
memcpy(&zout[82 + 27], &z[27 * ib2 + 82], 27);
}
if (ib3 != 3) {
memcpy(&zout[54], &z[27 * ib3], 27);
memcpy(&zout[82 + 54], &z[27 * ib3 + 82], 27);
}
cout << z << ";" << iout << endl;
}
}
}
}
next:;
}
}