login
Lexicographically smallest permutation of the natural numbers, such that a(n)+n and a(n)+n+1 are both composite numbers.
3

%I #12 Jul 07 2021 16:26:01

%S 7,6,5,4,3,2,1,12,11,10,9,8,13,18,17,16,15,14,19,24,23,22,21,20,25,28,

%T 27,26,33,32,31,30,29,34,39,38,37,36,35,40,43,42,41,46,45,44,47,50,49,

%U 48,53,52,51,56,55,54,57,58,59,60,61,62,65,64,63,66,67

%N Lexicographically smallest permutation of the natural numbers, such that a(n)+n and a(n)+n+1 are both composite numbers.

%C The permutation is self-inverse: a(a(n)) = n.

%H Reinhard Zumkeller, <a href="/A260933/b260933.txt">Table of n, a(n) for n = 1..10000</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%t a[n_]:=a[n]=(k=1;While[PrimeQ[k+n]||PrimeQ[k+n+1]||MemberQ[Array[a,n-1],k],k++];k);Array[a,100] (* _Giorgos Kalogeropoulos_, Jul 06 2021 *)

%o (Haskell)

%o import Data.List (delete)

%o a260933 n = a260933_list !! (n-1)

%o a260933_list = f 1 [1..] where

%o f x zs = g zs where

%o g (y:ys) = if a010051' (x + y) == 0 && a010051' (x + y + 1) == 0

%o then y : f (x + 1) (delete y zs) else g ys

%o (Python)

%o from sympy import isprime

%o def composite(n): return n > 1 and not isprime(n)

%o def aupton(terms):

%o alst, aset = [], set()

%o for n in range(1, terms+1):

%o an = 1

%o while True:

%o while an in aset: an += 1

%o if composite(an+n) and composite(an+n+1): break

%o an += 1

%o alst, aset = alst + [an], aset | {an}

%o return alst

%o print(aupton(67)) # _Michael S. Branicky_, Jul 06 2021

%Y Cf. A010051, A002808, A136798, A260936 (fixed points), A260822.

%K nonn

%O 1,1

%A _Reinhard Zumkeller_, Aug 04 2015