login
A348561
Primes where every other digit is 9 starting with the rightmost digit, and no other digit is 9.
4
19, 29, 59, 79, 89, 919, 929, 1949, 1979, 2909, 2939, 2969, 3919, 3929, 3989, 4909, 4919, 4969, 5939, 6949, 6959, 7919, 7949, 8929, 8969, 90989, 91909, 91939, 91969, 92959, 93949, 93979, 94949, 95929, 95959, 95989, 96959, 96979, 96989, 97919, 98909, 98929
OFFSET
1,1
LINKS
MATHEMATICA
Select[Prime@Range@10000, (n=#; s={EvenQ, OddQ}; t=Take[IntegerDigits@n, {#}]&/@Select[Range@i, #]&/@If[EvenQ[i=IntegerLength@n], s, Reverse@s]; Union@Flatten@First@t=={9}&&FreeQ[Flatten@Last@t, 9])&] (* Giorgos Kalogeropoulos, Oct 22 2021 *)
id[n_]:=IntegerDigits[n]; il[n_]:=IntegerLength[n]; eQ[n_]:=EvenQ[il[n]]&&AllTrue[Flatten[Position[id[n], 9]], EvenQ]&&Length[Cases[id[n], 9]]==il[n]/2; oQ[n_]:=OddQ[il[n]]&&
AllTrue[Flatten[Position[id[n], 9]], OddQ]&&Length[Cases[id[n], 9]]==(il[n]+1)/2;
Select[Prime[Range[10^5]], oQ[#]||eQ[#]&] (* Ivan N. Ianakiev, Oct 24 2021 *)
PROG
(Magma) f9:=func<n|forall{i:i in [1..#Intseq(n) by 2]| Intseq(n)[i] eq 9}>; fc:=func<n| forall{i:i in [2..#Intseq(n) by 2]| Intseq(n)[i] ne 9}>; [p:p in PrimesUpTo(100000)|f9(p) and fc(p)]; // Marius A. Burtea, Oct 22 2021
(Python)
from sympy import primerange as primes
def ok(p):
s = str(p)
if not all(s[i] == '9' for i in range(-1, -len(s)-1, -2)): return False
return all(s[i] != '9' for i in range(-2, -len(s)-1, -2))
print(list(filter(ok, primes(1, 98930)))) # Michael S. Branicky, Oct 22 2021
(Python) # faster version for generating large initial segments of sequence
from sympy import isprime
from itertools import product
def eo9(maxdigits): # generator for every other digit is 7, no other 7's
yield 9
for d in range(2, maxdigits+1):
if d%2 == 0:
for f in "12345678":
f9 = f + "9"
for p in product("012345678", repeat=(d-1)//2):
yield int(f9 + "".join(p[i]+"9" for i in range(len(p))))
else:
for p in product("012345678", repeat=(d-1)//2):
yield int("9" + "".join(p[i]+"9" for i in range(len(p))))
print(list(filter(isprime, eo9(5)))) # Michael S. Branicky, Oct 22 2021
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Lars Blomberg, Oct 22 2021
STATUS
approved