A057333
Numbers of n-digit primes that undulate.
Original entry on oeis.org
4, 20, 74, 347, 1743, 8385, 44355, 229952, 1235489, 6629026, 37152645, 202017712, 1142393492, 6333190658
Offset: 1
- C. A. Pickover, "Wonders of Numbers", Oxford New York 2001, Chapter 52, pp. 123-124, 316-317.
-
from sympy import isprime
def f(w,dir):
if dir == 1:
for s in w:
for t in range(int(s[-1])+1,10):
yield s+str(t)
else:
for s in w:
for t in range(0,int(s[-1])):
yield s+str(t)
def A057333(n):
c = 0
for d in '123456789':
x = d
for i in range(1,n):
x = f(x,(-1)**i)
c += sum(1 for p in x if isprime(int(p)))
if n > 1:
y = d
for i in range(1,n):
y = f(y,(-1)**(i+1))
c += sum(1 for p in y if isprime(int(p)))
return c # Chai Wah Wu, Apr 25 2021
A343677
Number of (2n+1)-digit undulating alternating palindromic primes.
Original entry on oeis.org
4, 6, 19, 34, 100, 241, 697, 1779, 6590, 16585, 57237, 179291, 591325, 1707010, 6520756, 18271423, 65212230, 210339179, 706823539
Offset: 0
-
from sympy import isprime
def f(w):
for s in w:
for t in range(int(s[-1])+1,10,2):
yield s+str(t)
def g(w):
for s in w:
for t in range(1-int(s[-1])%2,int(s[-1]),2):
yield s+str(t)
def A343677(n):
if n == 0:
return 4
c = 0
for d in '1379':
x = d
for i in range(1,n+1):
x = g(x) if i % 2 else f(x)
c += sum(1 for p in x if isprime(int(p+p[-2::-1])))
y = d
for i in range(1,n+1):
y = f(y) if i % 2 else g(y)
c += sum(1 for p in y if isprime(int(p+p[-2::-1])))
return c
A343462
Number of n-digit positive integers that undulate.
Original entry on oeis.org
9, 81, 525, 3105, 18939, 114381, 693129, 4195557, 25405586, 153820395, 931359050, 5639156409, 34143908573, 206733865761, 1251728824798, 7578945799704, 45888871327435, 277847147039527, 1682304127857000, 10185986079451152, 61673933253012813, 373422269794761171, 2260990733622821388
Offset: 1
a(2) = 81 as there are 90 2-digit positive integers (10, 11, ..., 99). Of those, 11, 22, ..., 99 do not undulate as there is a pair of consecutive digits that are equal. There are nine nonundulating 2-digit numbers, leaving 90-9 = 81 that do undulate.
134 does not undulate as there are two pairs of consecutive digits where the right one is in both cases either smaller or larger. (In this case 1 < 3 and 3 < 4.)
143 does undulate since 1 < 4 and 4 > 3.
- Eric Weisstein's World of Mathematics, Undulating Number.
- Index entries for linear recurrences with constant coefficients, signature (5,10,-20,-15,21,7,-8,-1,1).
-
first(n) = { my(res = vector(n), vup, vdown, nvup, nvdown); res[1] = 9; vup = vector(9, i, 1); vdown = vector(9, i, 1); for(i = 2, n, nvup = vector(9); nvdown = vector(9); nvdown[1] = vdown[9]; for(i = 2, 9, nvdown[i] = nvdown[i-1]+vup[i-1] ); for(i = 1, 8, nvup[i] = nvdown[9-i] ); vup = nvup; vdown = nvdown; res[i] = vecsum(vup)+vecsum(vdown)); res }
-
def aupton(terms):
up, dn, alst = [0] + [1]*9, [0] + [1]*9, [9]
for n in range(2, terms+1):
up_next = [sum(dn[j] for j in range(i)) for i in range(10)]
dn_next = [sum(up[j] for j in range(i+1, 10)) for i in range(10)]
up, dn = up_next, dn_next
alst.append(sum(up + dn))
return alst
print(aupton(22)) # Michael S. Branicky, Apr 16 2021
-
# alternate program as a linear system
import numpy as np
from sympy import Matrix
def aupton(terms):
x = Matrix([0] + [1]*9 + [0] + [1]*9)
c = Matrix([[1]*20])
z10 = np.zeros((10, 10), dtype=np.int64)
o10 = np.ones((10, 10), dtype=np.int64)
A = Matrix(np.block([[z10, np.tril(o10, -1)], [np.triu(o10, +1), z10]]))
alst = [9]
for n in range(2, terms+1):
x = A*x
alst.append((c*x)[0])
return alst
print(aupton(22)) # Michael S. Branicky, Apr 16 2021
Showing 1-3 of 3 results.
Comments