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.
%I A364479 #52 Feb 16 2025 08:34:06 %S A364479 7,313,383,11311,15451,30103,30803,35053,36263,71317,74047,94349, %T A364479 94649,95959,98689,1221221,1257521,1262621,1281821,1311131,1444441, %U A364479 1551551,1594951,1597951,1658561,1703071,1737371,1764671,1829281,1924291,1957591,1970791,1981891,1988891,3001003 %N A364479 Happy palindromic primes. %C A364479 All terms in the sequence are prime numbers that read the same backward and forward. Each term is a happy number, meaning it converges to 1 under the process of repeatedly summing the squares of its digits. The sequence is a subset of both the palindromic prime numbers (A002385) and the happy numbers (A007770). %C A364479 There are no happy palindromic primes with an even number of digits: every palindromic number with an even number of digits is divisible by 11, so 11 itself is the only palindromic prime, and it is not a happy number. %H A364479 Chai Wah Wu, <a href="/A364479/b364479.txt">Table of n, a(n) for n = 1..10000</a> %H A364479 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/HappyNumber.html">Happy Number</a>. %H A364479 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/PalindromicPrime.html">Palindromic Prime</a>. %e A364479 313 is a term as it is palindromic (can be reversed), is a prime and is happy: 3^2 + 1^2 + 3^2 = 19, 1^2 + 9^2 = 82, 8^2 + 2^2 = 68, 6^2 + 8^2 = 100, 1^2 + 0^2 + 0^2 = 1. %t A364479 happyQ[n_] := NestWhile[Plus @@ (IntegerDigits[#]^2) &, n, UnsameQ, All] == 1; Select[Prime[Range[220000]], PalindromeQ[#] && happyQ[#] &] (* _Amiram Eldar_, Jul 28 2023 *) %o A364479 (Python) %o A364479 def is_prime(num): %o A364479 return num > 1 and all(num % i != 0 for i in range(2, int(num ** 0.5) + 1)) %o A364479 def is_palindrome(num): %o A364479 return str(num) == str(num)[::-1] %o A364479 def is_happy(num): %o A364479 while num != 1 and num != 4: %o A364479 num = sum(int(digit) ** 2 for digit in str(num)) %o A364479 return num == 1 %o A364479 happy_palindromic_primes = [num for num in range(1, 10000000) if is_prime(num) and is_palindrome(num) and is_happy(num)] %o A364479 print(happy_palindromic_primes) %o A364479 (Python) %o A364479 from itertools import islice %o A364479 from sympy import isprime %o A364479 def A364479_gen(): # generator of terms %o A364479 n = 1 %o A364479 while True: %o A364479 for z in (1,3,5,7,9): %o A364479 for y in range(z*n, (z+1)*n): %o A364479 k, m = y//10, 0 %o A364479 while k >= 10: %o A364479 k, r = divmod(k, 10) %o A364479 m = 10*m + r %o A364479 if isprime(a:=y*n + 10*m + k): %o A364479 b = a %o A364479 while b not in {1,37,58,89,145,42,20,4,16}: %o A364479 b = sum((0, 1, 4, 9, 16, 25, 36, 49, 64, 81)[ord(d)-48] for d in str(b)) %o A364479 if b == 1: %o A364479 yield a %o A364479 n *= 10 %o A364479 A364479_list = list(islice(A364479_gen(),20)) # _Chai Wah Wu_, Aug 02 2023 %Y A364479 Intersection of A002385 and A007770. %K A364479 nonn,base %O A364479 1,1 %A A364479 _Simon R Blow_, Jul 26 2023