|
恢复>=5写法,保留n1=0
8行取5个的结果,用max(lv)+1求出最多4列,显示实际的数如下,把这些数前面统一加一个0,就是9行取5个,至少有4列的结果
with recursive n as (select i-1 n from generate_series(1,256)t(i))
,b as (select 1<<(i-1) b from generate_series(1,8)t(i))
,p as(select n1.n n1,n2.n n2
,count(*) cnt
from n n1, n n2, b
where n1.n<n2.n
and (n1.n#n2.n)&b.b>0
group by n1.n ,n2.n
having count(*)>=5)
,t as(select 1 lv,array[n1,n2]a, n1#n2 n3 from p where n1=0
union all
select lv+1,a||array[n],n3#n from t,n where n>a[lv+1] and n<>255-n3 and array_position(a,255-n)is null and lv+1= ( select count(*) from p q, unnest(a)
u(c) where n1=c and n2=n)
)
select * from t where lv=3 limit 20;
lv | a | n3
----+-----------------+---
3 | {0,126,185,199} | 0
3 | {0,125,186,199} | 0
3 | {0,124,187,199} | 0
3 | {0,123,188,199} | 0
3 | {0,122,189,199} | 0
3 | {0,121,190,199} | 0
3 | {0,126,181,203} | 0
3 | {0,125,182,203} | 0
3 | {0,124,183,203} | 0
3 | {0,119,188,203} | 0
3 | {0,118,189,203} | 0
3 | {0,117,190,203} | 0
3 | {0,126,179,205} | 0
3 | {0,123,182,205} | 0
3 | {0,122,183,205} | 0
3 | {0,119,186,205} | 0
3 | {0,118,187,205} | 0
3 | {0,115,190,205} | 0
3 | {0,125,179,206} | 0
3 | {0,123,181,206} | 0
(20 行记录)
|
|