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.

A360504 Concatenate the ternary strings for 1,2,...,n-1, n, n-1, ..., 2,1.

This page as a plain text file.
%I A360504 #31 Oct 01 2023 09:56:52
%S A360504 1,121,121021,1210111021,12101112111021,121011122012111021,
%T A360504 1210111220212012111021,12101112202122212012111021,
%U A360504 1210111220212210022212012111021,1210111220212210010110022212012111021,1210111220212210010110210110022212012111021,1210111220212210010110211010210110022212012111021
%N A360504 Concatenate the ternary strings for 1,2,...,n-1, n, n-1, ..., 2,1.
%C A360504 If the terms are read as ternary strings and converted to base 10, we get A260853. For example, a(3) = 121021_3 = 439_10, which is A260853(3). This is a prime. What is the next prime term?
%C A360504 If the terms are read as decimal numbers, which of them are primes? a(3) = 121021_10 is a decimal prime, but what is the next one?  It is a surprise that 121021 is a prime in both base 3 and base 10.
%H A360504 Winston de Greef, <a href="/A360504/b360504.txt">Table of n, a(n) for n = 1..123</a>
%H A360504 <a href="/index/Mo#MWP">Index entries for sequences related to Most Wanted Primes video</a>
%e A360504 To get a(3) we concatenate 1, 2, 10, 2, and 1, getting 121021.
%p A360504 t:= n-> (l-> parse(cat(seq(l[-i], i=1..nops(l)))))(convert(n, base, 3)):
%p A360504 a:= n-> parse(cat(map(t, [$1..n, n-i$i=1..n-1])[])):
%p A360504 seq(a(n), n=1..12);  # _Alois P. Heinz_, Feb 17 2023
%t A360504 Table[FromDigits[Flatten[Join[IntegerDigits[#,3]&/@Range[n],IntegerDigits[#,3]&/@ Range[ n-1,1,-1]]]],{n,20}] (* _Harvey P. Dale_, Oct 01 2023 *)
%o A360504 (Python)
%o A360504 from sympy.ntheory import digits
%o A360504 def a(n): return int("".join("".join(map(str, digits(k, 3)[1:])) for k in list(range(1, n+1))+list(range(n-1, 0, -1))))
%o A360504 print([a(n) for n in range(1, 16)]) # _Michael S. Branicky_, Feb 18 2023
%o A360504 (Python) # faster version for initial segment of sequence
%o A360504 from sympy.ntheory import digits
%o A360504 from itertools import count, islice
%o A360504 def agen(): # generator of terms
%o A360504     sf, sr = "", ""
%o A360504     for n in count(1):
%o A360504         sn = "".join(map(str, digits(n, 3)[1:]))
%o A360504         sf += sn
%o A360504         yield int(sf + sr)
%o A360504         sr = sn + sr
%o A360504 print(list(islice(agen(), 15))) # _Michael S. Branicky_, Feb 18 2023
%Y A360504 Cf. A007089, A360502, A360503.
%Y A360504 This is the ternary analog of A173426.
%K A360504 nonn,base
%O A360504 1,2
%A A360504 _N. J. A. Sloane_, Feb 17 2023