A158652 Any two consecutive digits in the sequence sum up to a prime.
1, 2, 3, 4, 7, 41, 43, 47, 49, 83, 85, 89, 202, 302, 303, 411, 412, 502, 503, 830, 2020, 2021, 2023, 2025, 2029, 2030, 2032, 3020, 3021, 4111, 4112, 5020, 5021, 6111, 6112, 9202, 9203, 20202, 30202, 30203, 41111, 41112, 50202, 50203, 83020, 202020
Offset: 1
Links
- Robert G. Wilson v, Table of n, a(n) for n=1..100
- Eric Angelini, Chiffres consecutifs dans quelques suites
- Eric Angelini, Chiffres consecutifs dans quelques suites [Cached copy, with permission]
Programs
-
Mathematica
f[s_List] := Block[{k = s[[ -1]] + 1, ls = Mod[ s[[ -1]], 10]}, While[ Union@ PrimeQ[ Plus @@@ Partition[ Join[{ls}, IntegerDigits@ k], 2, 1]] != {True}, k++ ]; Append[s, k]]; Nest[f, {1}, 45] (* Robert G. Wilson v, Apr 05 2009 *)
-
Python
from itertools import count, islice allowed = {"0":"2357", "1":"1246", "2":"01359", "3":"0248", "4":"1379", "5":"0268", "6":"157", "7":"046", "8":"359", "9":"248"} def cgen(seed, digits, geq="0"): # numbers satisfying the condition if digits == 1: yield from (c for c in allowed[seed] if c >= geq); return for f in (c for c in allowed[seed] if c >= geq): yield from (f + r for r in cgen(f, digits-1)) def nextc(k): # next element of cgen greater than k s = str(k) for d in count(len(s)): geq = s[0] if d == len(s) else "1" for c in map(int, cgen(s[-1], d, geq=geq)): if c > k: return c def agen(): an = 1 for n in count(1): yield an; an = nextc(an) print(list(islice(agen(), 40))) # Michael S. Branicky, Jul 12 2022
Comments