A088643 Triangle read by rows: row n >= 1 is obtained as follows. Start with n, next term is always largest number m with 1 <= m < n which has not yet appeared in that row and such that m + previous term in the row is a prime. Stop when no further m can be found.
1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 2, 3, 4, 1, 6, 5, 2, 3, 4, 1, 7, 6, 5, 2, 3, 4, 1, 8, 5, 6, 7, 4, 3, 2, 1, 9, 8, 5, 6, 7, 4, 3, 2, 1, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 11, 8, 9, 10, 7, 6, 5, 2, 3, 4, 1, 12, 11, 8, 9, 10, 7, 6, 5, 2, 3, 4, 1, 13, 10, 9, 8, 11, 12, 7, 6, 5, 2, 3, 4, 1, 14, 9, 10, 13, 6, 11, 12, 7, 4, 3, 8, 5, 2, 1
Offset: 1
Examples
For example, the 20th row is 20, 17, 14, 15, 16, 13, 18, 19, 12, 11, 8, 9, 10, 7, 6, 5, 2, 3, 4, 1. Triangle begins: 1; 2, 1; 3, 2, 1; 4, 3, 2, 1; 5, 2, 3, 4, 1; 6, 5, 2, 3, 4, 1; (...)
Links
- Reinhard Zumkeller, Rows n = 1..150 of triangle, flattened
- Peter Munn, Illustration of the relationship between this sequence, A132075 and A255312.
- J. W. Roche, Letter regarding "M. J. Kenney and S. J. Bezuszka, Calendar problem 12, 1997", Mathematics Teacher, 91 (1998), 155.
Crossrefs
Programs
-
Haskell
import Data.List (delete) a088643_tabl = map a088643_row [1..] a088643 n k = a088643_row n !! (k-1) a088643_row n = n : f n [n-1, n-2 .. 1] where f u vs = g vs where g [] = [] g (x:xs) | a010051 (x + u) == 1 = x : f x (delete x vs) | otherwise = g xs -- Reinhard Zumkeller, Jan 05 2013
-
Maple
A088643 := proc(n,k) option remember ; local m,c; if n = 1 then 1; else if k = 1 then return n; else for m from n-1 to 1 by -1 do if not member(m,[seq(procname(n,c),c=1..k-1)]) then if isprime(m+procname(n,k-1)) then return m; end if ; end if; end do: end if; end if; end proc: for n from 1 to 10 do for k from 1 to n do printf("%d ",A088643(n,k)) ; end do: printf("\n") ; end do: # R. J. Mathar, Aug 18 2021
-
Mathematica
t[n_, 1] := n; t[n_, k_] := t[n, k] = For[m = n-1, m >= 1, m--, If[ PrimeQ[m + t[n, k-1] ] && FreeQ[ Table[ t[n, j], {j, 1, k-1} ], m], Return[m] ] ]; Table[ t[n, k], {n, 1, 14}, {k, 1, n} ] // Flatten (* Jean-François Alcover, Apr 03 2013 *)
-
PARI
apply( {A088643_row(n, t=List(-[1-n..-1]))=vector(n,i, i>1 && for(j=1,#t, isprime(n+t[j]) && [n=t[j], listpop(t,j), break]);n)}, [1..20]) \\ M. F. Hasler, Aug 02 2021; improved Aug 03 2021 after PARI below
-
PARI
row(n) = { my(res = vector(n), todo = List([1..n-1])); res[1] = n; for(i = 1, n - 1, forstep(j = #todo, 1, -1, if(isprime(res[i] + todo[j]), res[i+1] = todo[j]; listpop(todo, j); next(2) ) ) ); res } \\ David A. Corneth, Aug 02 2021
Formula
A255313(n,k) = T(n,k-1) + T(n,k), n > 0 and 1 <= k <= n. - Reinhard Zumkeller, Feb 22 2015
Extensions
More terms from David Wasserman, Aug 16 2005
Comments