A132163 Triangle read by rows. For row n, start with 1 but from the second term onwards always choose the largest positive integer between 1 and n inclusive that i) has not already appeared in the row ii) gives a prime when added to the previous term. Stop if no such integer can be found.
1, 1, 2, 1, 2, 3, 1, 4, 3, 2, 1, 4, 3, 2, 5, 1, 6, 5, 2, 3, 4, 1, 6, 7, 4, 3, 2, 5, 1, 6, 7, 4, 3, 8, 5, 2, 1, 6, 7, 4, 9, 8, 5, 2, 3, 1, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 10, 9, 8, 11, 6, 7, 4, 3, 2, 5, 1, 12, 11, 8, 9, 10, 7, 6, 5, 2, 3, 4
Offset: 1
Links
- Reinhard Zumkeller, Rows n = 1..150 of triangle, flattened
Crossrefs
This sequence is a variation on A088643.
Programs
-
Haskell
import Data.List (delete) a132163_tabl = map a132163_row [1..] a132163 n k = a132163_row n !! (k-1) a132163_row n = 1 : f 1 [n, n-1 .. 2] 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
-
Mathematica
t[, 1] = 1; t[n, k_] := t[n, k] = For[ j = n, j > 1, j--, If[ PrimeQ[ t[n, k-1] + j] && FreeQ[ Table[ t[n, m], {m, 1, k-1}], j], Return[j] ] ]; Table[ t[n, k], {n, 1, 12}, {k, 1, n}] // Flatten (* Jean-François Alcover, Apr 02 2013 *)
Comments