login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A332267
a(1) = 1; a(2) = 2; for n > 2, if a(n-1) > a(n-2) then a(n) = a(n-1) - a(n-2), otherwise a(n) = number of occurrences of a(n-1).
0
1, 2, 1, 2, 1, 3, 2, 3, 1, 4, 3, 3, 4, 1, 5, 4, 3, 5, 2, 4, 2, 5, 3, 6, 3, 7, 4, 5, 1, 6, 5, 5, 6, 1, 7, 6, 4, 6, 2, 6, 4, 7, 3, 8, 5, 7, 2, 7, 5, 8, 3, 9, 6, 7, 1, 8, 7, 7, 8, 1, 9, 8, 5, 9, 4, 8, 4, 9, 5, 10, 5, 11, 6, 8, 2, 8, 6, 9, 3, 10, 7, 9, 2, 9, 7
OFFSET
1,2
EXAMPLE
a(9) = a(8) - a(7) = 3-2 = 1. The number of occurrences of 1 up to that point is 4, so a(10) = 4.
PROG
(PARI) a=[1, 2]; for(n=2, 99, a=concat(a, if(a[n]>a[n-1], a[n]-a[n-1], sum(i=1, n, a[i]==a[n])))); a \\ M. F. Hasler, May 22 2020, brackets fixed by David A. Corneth, May 22 2020
(PARI) first(n) = {n = max(n, 2); res = vector(n); freqs = vector(2); res[1] = 1; res[2] = 2; freqs[1] = 1; freqs[2] = 1; for(i = 3, n, d = res[i-1] - res[i-2]; if(d > 0, res[i] = d; freqs[d]++ , fr = freqs[res[i-1]]; res[i] = fr; if(fr > #freqs, freqs = concat(freqs, vector(fr - #freqs)); ); freqs[fr]++ ) ); res } \\ David A. Corneth, May 22 2020
CROSSREFS
Sequence in context: A353304 A376719 A305974 * A161148 A143773 A323524
KEYWORD
nonn,easy,look
AUTHOR
Ali Sada, May 04 2020
STATUS
approved