cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A125002 Let p = prime(n); a(n) = number of primes q with same number of digits as p that can be obtained from p by changing one digit.

This page as a plain text file.
%I A125002 #16 May 10 2022 02:11:02
%S A125002 3,3,3,3,7,8,7,7,6,5,5,5,6,7,6,6,5,5,5,6,7,6,6,5,4,10,8,11,11,6,8,9,9,
%T A125002 10,6,7,11,9,9,8,7,6,10,9,11,9,7,8,7,6,7,7,7,7,8,9,5,7,7,7,9,6,8,6,7,
%U A125002 8,5,8,9,6,7,6,8,7,6,8,4,8,8,10,8,6,9,6,11,5,8,7,8,8,7,7,5,8,8,5,7,5,6,6
%N A125002 Let p = prime(n); a(n) = number of primes q with same number of digits as p that can be obtained from p by changing one digit.
%H A125002 Reinhard Zumkeller, <a href="/A125002/b125002.txt">Table of n, a(n) for n = 1..10000</a>
%e A125002 The 5th prime 11 leads to 7 other primes: 13,17,19,31,41,61,71, hence a(5)=7.
%e A125002 a(6)=8, p=13, q={11,17,19,23,43,53,73,83}
%e A125002 a(7)=7, p=17, q={11,13,19,37,47,67,97}
%e A125002 a(8)=7, p=19, q={11,13,17,29,59,79,89}
%e A125002 a(9)=6, p=23, q={29,13,43,53,73,83}
%e A125002 a(10)=5, p=29, q={23,19,59,79,89}
%p A125002 A125002 := proc(n) local p,digs,res,r,d; p := ithprime(n) ; digs := convert(p,base,10) ; res := 0 ; for d from 1 to nops(digs) do for r from 0 to 9 do if r <> op(d,digs) and ( d <> nops(digs) or r > 0) then q := p-(op(d,digs)-r)*10^(d-1) ; if isprime(q) then res := res+1 ; fi ; fi ; od ; od ; RETURN(res) ; end ; for n from 1 to 100 do printf("%d,",A125002(n)) ; od ; # _R. J. Mathar_, Jan 13 2007
%o A125002 (Haskell)
%o A125002 import Data.List (delete)
%o A125002 a125002 n = sum $ map (a010051' . read) $
%o A125002                   tail $ concatMap (f pds) [0 .. length pds - 1] where
%o A125002    pds = show $ a000040 n
%o A125002    f ws k = [us ++ [y] ++ vs |
%o A125002             let (us, v:vs) = splitAt k ws, y <- delete v "0123456789"]
%o A125002 -- _Reinhard Zumkeller_, Jul 06 2014
%o A125002 (Python)
%o A125002 from sympy import isprime, sieve
%o A125002 def neighbors(s):
%o A125002     digs = "0123456789"
%o A125002     ham1 = (s[:i]+d+s[i+1:] for i in range(len(s)) for d in digs if d!=s[i])
%o A125002     yield from (h for h in ham1 if h[0] != '0')
%o A125002 def a(n):
%o A125002     return sum(1 for s in neighbors(str(sieve[n])) if isprime(int(s)))
%o A125002 print([a(n) for n in range(1, 101)]) # _Michael S. Branicky_, May 09 2022
%Y A125002 Cf. A000040.
%K A125002 nonn,base
%O A125002 1,1
%A A125002 _Zak Seidov_, Jan 08 2007
%E A125002 Corrected and extended by _Hans Havermann_ and _R. J. Mathar_, Jan 08 2007