%I
%S 1,3,6,2,7,10,15,9,21,28,12,36,14,45,55,17,66,19,78,22,91,105,24,120,
%T 26,136,29,153,171,31,190,33,210,35,231,253,38,276,40,300,42,325,44,
%U 351,378,47,406,49,435,51,465,53,496,56,528,561
%N a(a(n)) is a triangular number.
%C To build T: always use the smallest integer not yet present in T and not leading to a contradiction.
%C All triangular numbers appear in their natural order.
%C Density of T: it appears that more than 50% of the terms are triangular.
%C _Arie Groeneveld_ computed a million terms in less than 1.5 seconds using the language J.
%D Eric Angelini, Postings to Sequence Fans Mailing List, Mar 02 2011 and Mar 03 2011.
%e T = 1,... meaning that the first term of T is a triangular number (true)
%e The next term can't be 2 as '2' would mean that the second term of T is a triangular term  which is false, 2 is not a triangular number  see A000217
%e Then:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,
%e We have to put a triangular number 't' in third position:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,t,
%e Thus:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,
%e Thus:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,* * t
%e Now we need to replace the first star with "the smallest integer not yet present in T and not leading to a contradiction":
%e Thus:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,2,* t
%e Next star is replaced by "the smallest etc." which can't be 4, 5 or 6  thus 7 (the 4th term of T is not a triangular number, the 5th neither  as it would be '5'  and '6' is already in T):
%e Thus:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,2,7,t
%e and:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,2,7,t t
%e We replace the next two 't' with two triangular numbers:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,2,7,10,15,
%e and mark accordingly the 10th and 15th term of T with 't':
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,2,7,10,15, t t
%e The next 'hole' we have to fill in T is the 8th; we put '9':
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,2,7,10,15,9, t t
%e and we add accordingly a 't' in 9th position:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,2,7,10,15,9,t, t t
%e Now two more triangular numbers:
%e n : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
%e T = 1,3,6,2,7,10,15,9,21,28, t
%e ... etc.
%o (J)
%o arr249558 =: monad define
%o n=. # (,8+{:)^:(y>+/)^:_[ 6 15
%o ti=. (#~y>])+/\ 0 1 1 3 1 2, ;,&2 2&.>^:(<n) 1 2 2;3$<1 2 2 2
%o tn=. (#ti){.+/\ 1+i.y
%o ni=. (#~y>])+/\ 3 1 3, ;,& 2 2&.>^:(<n) 3 2;3$<3 2 2
%o nn=. (# ni){.+/\ 2 5 2 3 2 3 2, ;,&2 2&.>^:(<n)3 2 2;3$<3 2 2 2
%o (tn,nn) /: ti,ni
%o )
%o _Arie Groeneveld_, Dec 02 2014
%Y Cf. A000217.
%K nonn
%O 1,2
%A _N. J. A. Sloane_, Nov 01 2014
