This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A363962 #22 Aug 26 2023 02:52:43 %S A363962 1,2,6,24,19,3,21,13,4,40,29,17,8,112,97,81,12,216,5,100,7,154,131,4, %T A363962 100,74,47,1316,11,330,299,267,234,200,165,129,92,54,15,10,410,368, %U A363962 325,281,236,190,27,1296,1247,1197,1146,1094,1041,38,2090,2034,1977,1919,1860,1800,1739,1677,1614 %N A363962 a(1)=1; for n > 1, if n appears in the sequence then a(n) = lastindex(n), where lastindex(n) is the index of the last appearance of n. Otherwise a(n) = a(n-1) - n unless that result is already in the sequence or would be negative; otherwise, a(n) = a(n-1) * n. %e A363962 a(6) = 3, as a(3) = 6 = n, thus a(6) = 3. %e A363962 a(28) = 1316 because subtracting 28 from the previous term (47) would give 19, which is already in the sequence, so multiply 47 by 28 to get 1316. %e A363962 a(100) = 25, as a(25) = 100 = n, thus a(100) = 25. %t A363962 a[1] = 1; a[n_] := a[n] = Module[{s = Array[a, n - 1], a1}, If[MemberQ[s, n], Position[s, n][[-1, 1]], a1 = a[n - 1] - n; If[a1 < 0 || MemberQ[s, a1], a[n - 1]*n, a1]]]; Array[a, 100] (* _Amiram Eldar_, Jul 23 2023 *) %o A363962 (MATLAB) %o A363962 function a = A363962( max_n ) %o A363962 a = 1; %o A363962 for n = 2:max_n %o A363962 r = find(a == n,1,'last'); %o A363962 if ~isempty(r) %o A363962 a(n) = r; %o A363962 else %o A363962 k = a(n-1) - n; %o A363962 if k > 0 && isempty(find(a == k, 1)) %o A363962 a(n) = k; %o A363962 else %o A363962 a(n) = a(n-1) * n; %o A363962 end %o A363962 end %o A363962 end %o A363962 end % _Thomas Scheuerle_, Jul 03 2023 %Y A363962 Cf. A005132, A340612, A354833, A362332. %K A363962 nonn %O A363962 1,2 %A A363962 _Kelvin Voskuijl_, Jun 29 2023