\\ Copyright 2020 Kevin Ryde
\\
\\ This file is part of Math-NumSeq.
\\
\\ Math-NumSeq is free software; you can redistribute it and/or modify
\\ it under the terms of the GNU General Public License as published by the
\\ Free Software Foundation; either version 3, or (at your option) any later
\\ version.
\\
\\ Math-NumSeq is distributed in the hope that it will be useful, but
\\ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\\ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\\ for more details.
\\
\\ You should have received a copy of the GNU General Public License along
\\ with Math-NumSeq. If not, see .
default(recover,0);
default(strictargs,1);
\\ A336231 integers with even num 0-bits between each pair of 1-bits
\\
\\ Code by Michel Marcus in A336231
isok(n) =
{
my(vpos = select(x->(x==1), binary(n), 1));
for(i=1, #vpos-1, if((vpos[i+1]-vpos[i]-1) % 2, return(0)));
return(1);
}
a_by_fibonacci(n) =
{
my(k=0); while(n>=fibonacci(k+3),k++);
k--;
n-=fibonacci(k+3);
my(ret=1<=0,
if(n>=fibonacci(k+1),
n-=fibonacci(k+1); ret+=1<=fibonacci(k),k++); \
\\ if(debug,print("top "k)); \
\\ k--; \
\\ my(ret=1<<(k-3)); \
\\ n -= fibonacci(k); \
\\ k-=2; \
\\ while(k-->0, \
\\ if(debug,print("k="k" "n" cmp ",fibonacci(k))); \
\\ if(n>=fibonacci(k), \
\\ if(debug,print("bit "k)); \
\\ ret+=1<<(k-1); \
\\ n-= fibonacci(k); \
\\ , \
\\ k--)); \
\\ ret;
\\
\\ A336231(n) = \
\\ my(k=1,x=1,y=2,debug=0); \
\\ while(n>=y, [x,y]=[y,x+y];k++); \
\\ if(debug,print("top "k" xy "x" "y)); \
\\ n-=x; [x,y]=[2*x-y,y-x]; k-=2; \
\\ my(ret=1<=0, \
\\ if(debug,print("k="k" "n" cmp x=",x," y="y)); \
\\ if(n>=x, \
\\ if(debug,print("bit "k)); \
\\ n-=x; ret+=1<=x+y, [x,y]=[y,x+y];k++); \
\\ n-=y; [x,y]=[y-x,x]; k--; \
\\ my(ret=1<= 0, \
\\ if(n>=x, n-=x;ret+=1<=x+y-1, [x,y]=[y,x+y];k++); \
\\ n-=y; [x,y]=[y-x,x]; k--; \
\\ my(ret=1<= 0, \
\\ if(n+1>=x, n-=x;ret+=1<=x+y, [x,y]=[y,x+y];k++); \
\\ n-=y; listput(l,y); [x,y]=[y-x,x]; k--; \
\\ my(ret=1<= 0, \
\\ if(n>=x, n-=x;ret+=1<