%I #67 Dec 25 2022 08:29:49
%S 1,3,2,6,5,4,10,9,8,7,15,14,13,12,11,21,20,19,18,17,16,28,27,26,25,24,
%T 23,22,36,35,34,33,32,31,30,29,45,44,43,42,41,40,39,38,37,55,54,53,52,
%U 51,50,49,48,47,46,66,65,64,63,62,61,60,59,58,57,56,78,77,76
%N Take the sequence of natural numbers (A000027) and reverse successive subsequences of lengths 1,2,3,4,... .
%C Ramanujan theta functions: f(q) (see A121373), phi(q) (A000122), psi(q) (A010054), chi(q) (A000700).
%C The rectangular array having A038722 as antidiagonals is the transpose of the rectangular array given by A000217. Column 1 of array A038722 is A000124 (central polygonal numbers). Array A038722 is the dispersion of the complement of A000124. - _Clark Kimberling_, Apr 05 2003
%C a(n) is the smallest number not yet in the sequence such that n + a(n) is one more than a square. - _Franklin T. Adams-Watters_, Apr 06 2009
%C From _Hieronymus Fischer_, Apr 30 2012: (Start)
%C A reordering of the natural numbers.
%C The sequence is self-inverse in that a(a(n)) = n.
%C Also: a(1) = 1, a(n) = m (where m is the least triangular number > a(k) for 1 <= k < n), if the minimal natural number not yet in the sequence is greater than a(n-1), otherwise a(n) = a(n-1)-1. (End)
%D Suggested by correspondence with Michael Somos.
%D R. Honsberger, "Ingenuity in Mathematics", Table 10.4 on page 87.
%H Hieronymus Fischer, <a href="/A038722/b038722.txt">Table of n, a(n) for n = 1..11401</a>
%H Michael Somos, <a href="/A010815/a010815.txt">Introduction to Ramanujan theta functions</a>
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/RamanujanThetaFunctions.html">Ramanujan Theta Functions</a>
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F a(n) = (sqrt(2n-1) - 1/2)*(sqrt(2n-1) + 3/2) - n + 2 = A061579(n-1) + 1. Seen as a square table by antidiagonals, T(n, k) = k + (n+k-1)*(n+k-2)/2, i.e., the transpose of A000027 as a square table.
%F G.f.: g(x) = (x/(1-x))*(psi(x) - x/(1-x) + 2*Sum_{k>=0} k*x^(k*(k+1)/2)) where psi(x) = Sum_{k>=0} x^(k*(k+1)/2) = (1/2)*x^(-1/8)*theta_2(0,x^(1/2) is a Ramanujan theta function. - _Hieronymus Fischer_, Aug 08 2007
%F a(n) = floor(sqrt(2*n) + 1/2)^2 - n + 1. - _Clark Kimberling_, Jun 05 2011; corrected by _Paul D. Hanna_, Jun 27 2011
%F From _Hieronymus Fischer_, Apr 30 2012: (Start)
%F a(n) = a(n-1)-1, if a(n-1)-1 > 0 is not in the set {a(k)| 1<=k<n}, otherwise a(n) = m, where m is the least triangular number not yet in the sequence.
%F a(n) = n for n = 2k(k+1)+1, k >= 0.
%F a(n+1) = (m+2)(m+3)/2, if 8a(n)-7 is a square of an odd number, otherwise a(n+1) = a(n)-1, where m = (sqrt(8a(n)-7)-1)/2.
%F a(n) = ceiling((sqrt(8n+1)-1)/2)^2 - n + 1. (End)
%F G.f. as rectangular array: x*y*(1 - (1 + x)*y + (1 - x + x^2)*y^2)/((1 - x)^3*(1 - y)^3). - _Stefano Spezia_, Dec 25 2022
%e The rectangular array view is
%e 1 2 4 7 11 16 22 29 37 46
%e 3 5 8 12 17 23 30 38 47 57
%e 6 9 13 18 24 31 39 48 58 69
%e 10 14 19 25 32 40 49 59 70 82
%e 15 20 26 33 41 50 60 71 83 96
%e 21 27 34 42 51 61 72 84 97 111
%e 28 35 43 52 62 73 85 98 112 127
%e 36 44 53 63 74 86 99 113 128 144
%e 45 54 64 75 87 100 114 129 145 162
%e 55 65 76 88 101 115 130 146 163 181
%t (* Program generates dispersion array T of the increasing sequence f[n] *)
%t r=40; r1=12; c=40; c1=12; f[n_] := Floor[1/2+Sqrt[2n]]
%t (* complement of column 1 *)
%t mex[list_] := NestWhile[#1 + 1 &, 1, Union[list][[#1]] <= #1 &, 1, Length[Union[list]]]
%t rows = {NestList[f, 1, c]};
%t Do[rows = Append[rows, NestList[f, mex[Flatten[rows]], r]], {r}];
%t t[i_, j_] := rows[[i, j]];
%t TableForm[Table[t[i, j], {i, 1, r1}, {j, 1, c1}]]
%t (* A038722 array *)
%t Flatten[Table[t[k, n - k + 1], {n, 1, c1}, {k, 1, n}]]
%t (* A038722 sequence *) (* _Clark Kimberling_, Jun 06 2011 *)
%t Table[ n, {m, 12}, {n, m (m + 1)/2, m (m - 1)/2 + 1, -1}] // Flatten (* or *)
%t Table[ Ceiling[(Sqrt[8 n + 1] - 1)/2]^2 - n + 1, {n, 78}] (* _Robert G. Wilson v_, Jun 27 2014 *)
%t With[{nn=20},Reverse/@TakeList[Range[(nn(1+nn))/2],Range[nn]]//Flatten] (* Requires Mathematica version 11 or later *) (* _Harvey P. Dale_, Dec 14 2017 *)
%o (PARI) a(n)=local(t=floor(1/2+sqrt(2*n))); if(n<1, 0, t^2-n+1) /* _Paul D. Hanna_ */
%o (Haskell)
%o a038722 n = a038722_list !! (n-1)
%o a038722_list = concat a038722_tabl
%o a038722_tabl = map reverse a000027_tabl
%o a038722_row n = a038722_tabl !! (n-1)
%o -- _Reinhard Zumkeller_, Nov 08 2013
%Y A self-inverse permutation of the natural numbers.
%Y Cf. A000027, A020703.
%Y Cf. A132666, A132664, A132665, A132674.
%Y Cf. A056011 (boustrophedon).
%Y Cf. A000122, A000700, A010054, A121373.
%Y Cf. A000124, A000217.
%Y Cf. A061579.
%K nonn,easy,tabl
%O 1,2
%A _N. J. A. Sloane_, May 02 2000