login
Composite numbers not ending in zero that yield a prime when turned upside down.
3

%I #21 Dec 26 2022 15:08:52

%S 68,116,118,161,166,169,188,608,616,1006,1018,1066,1081,1096,1106,

%T 1108,1118,1169,1186,1606,1618,1808,1816,1898,1916,1918,1969,1981,

%U 1988,1996,6001,6008,6016,6098,6188,6191,6196,6616,6668,6698,6808,6809,6881,6896

%N Composite numbers not ending in zero that yield a prime when turned upside down.

%H Robert Israel and Reinhard Zumkeller, <a href="/A048889/b048889.txt">Table of n, a(n) for n = 1..10000</a> (a(1) to a(1048) from Reinhard Zumkeller)

%e 68 is not prime, yet when turned upside down gives 89 which is prime.

%p N:= 1000: # to get a(1) to a(N)

%p count:= 0:

%p for q from 1 while count < N do

%p if q mod 5 <> 0 then

%p L:= convert(q,base,5);

%p m:= nops(L);

%p Lx:= subs(2=6,3=8,4=9,L);

%p x:= add(Lx[i]*10^(i-1),i=1..m);

%p if isprime(x) then next fi;

%p Ly:= subs(2=9,3=8,4=6,L);

%p y:= add(Ly[-i]*10^(i-1),i=1..m);

%p if isprime(y) then

%p count:= count+1;

%p A[count]:= x;

%p fi

%p fi

%p od:

%p seq(A[i],i=1..count); # _Robert Israel_, Jul 11 2016

%t Select[Range[7000],CompositeQ[#]&&Mod[#,10]!=0&&SubsetQ[{0,1,6,8,9}, IntegerDigits[ #]]&&PrimeQ[FromDigits[Reverse[IntegerDigits[#]]/.{6->9,9->6}]]&] (* _Harvey P. Dale_, Dec 26 2022 *)

%o (Haskell)

%o import Data.List (intersect)

%o import Numeric (readInt)

%o import Data.Char (digitToInt)

%o a048889 n = a048889_list !! (n-1)

%o a048889_list = filter f a002808_list where

%o f n = n `mod` 10 > 0 &&

%o null ("23547" `intersect` show n) &&

%o (a010051 (fst $ head $ readInt 10 (const True) ud $ ns) == 1)

%o where ns = reverse $ show n

%o ud '6' = 9

%o ud '9' = 6

%o ud z = digitToInt z

%o -- _Reinhard Zumkeller_, Aug 11 2011

%o (Python)

%o from itertools import product

%o from sympy import isprime

%o A048889_list = [m for m in (int(''.join(d)) for d in product('01689',repeat=6)) if m % 10 and not isprime(m) and isprime(int(str(m)[::-1].translate(''.maketrans('69','96'))))] # _Chai Wah Wu_, Sep 14 2021

%Y Cf. A002808, A010051.

%K base,easy,nonn,nice

%O 1,1

%A _G. L. Honaker, Jr._