login
a(1)=1; for n > 1, 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.
3

%I #36 Jul 02 2023 22:31:54

%S 1,2,6,24,19,13,91,83,74,64,53,41,28,14,210,194,177,159,140,120,99,77,

%T 54,30,5,130,103,75,46,16,496,464,431,397,362,326,289,251,212,172,131,

%U 89,3827,3783,3738,3692,3645,3597,3548,3498,3447,3395,3342,3288,3233,3177

%N a(1)=1; for n > 1, 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.

%H Rémy Sigrist, <a href="/A354833/b354833.txt">Table of n, a(n) for n = 1..22279</a>

%e a(7) = 91 because from the previous term (13) you cannot subtract 7, because you would get 6, which is already in the sequence, so multiply 13 by 7 to get 91.

%t a[1] = 1; a[n_] := a[n] = Module[{s = Array[a, n - 1], d}, If[(d = a[n - 1] - n) < 0 || MemberQ[s, d], n * a[n - 1], d]]; Array[a, 50] (* _Amiram Eldar_, Jun 07 2022 *)

%o (PARI) { seen = Map(); v = 1; for (n=1, 56, mapput(seen, v, 0); print1 (v", "); v=if (mapisdefined(seen, w=v-(n+1)) || w<0, v*(n+1), w)) } \\ _Rémy Sigrist_, Jul 02 2022

%o (Python)

%o from itertools import count, islice

%o def agen():

%o an, seen = 1, {1}

%o yield 1

%o for n in count(2):

%o t = an - n

%o an = t if t not in seen and t >= 0 else an*n

%o yield an

%o seen.add(an)

%o print(list(islice(agen(), 56))) # _Michael S. Branicky_, Jul 02 2022

%Y Cf. A005132, A200044.

%Y Cf. A355457 (Multiplicative steps).

%K nonn

%O 1,2

%A _Kelvin Voskuijl_, Jun 07 2022