OFFSET
1,1
LINKS
N. J. A. Sloane, Maple implementations of XORnos and DIFF
FORMULA
a(n) = 2 + Sum_{k=1..n-1} 2^A059662(k). - Pontus von Brömssen, Jan 07 2023
MAPLE
flip_primes_asc_search := proc(a, upto_bit, upto_length) local i, n, t; if(nops(a) >= upto_length) then RETURN(a); fi; t := a[nops(a)]; for i from 0 to upto_bit do n := XORnos(t, (2^i)); if(isprime(n) and (n > t)) then print([op(a), n]); RETURN(flip_primes_asc_search([op(a), n], upto_bit, upto_length)); fi; od; RETURN([op(a), `and no more`]); end;
flip_primes_asc_search([2], 512, 21);
MATHEMATICA
uptobit = 512; uptolength = 17; Clear[f]; f[a_] := f[a] = Module[{n, i, t}, If[Length[a] >= uptolength, Return[a]]; t = a[[-1]]; For[i = 0, i <= uptobit, i++, n = BitXor[t, 2^i]; If[PrimeQ[n] && n > t, Return[f[Append[ a, n]]]]]]; A059661 = f[{2}] (* Jean-François Alcover, Mar 07 2016, adapted from Maple *)
PROG
(Python)
from sympy import isprime
from itertools import islice
def agen():
an, bit = 2, 1
while True:
yield an
while an&bit or not isprime(an+bit): bit <<= 1
an += bit; bit = 1
print(list(islice(agen(), 17))) # Michael S. Branicky, Oct 01 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Feb 03 2001
STATUS
approved