A382482 a(1) = 1. Let a(n) be the most recently defined term. At each step, check for an undefined term with index < n. If such a term exists, then where i is the earliest such index, set a(i) = a(n) - (n - i). If no such term exists, then where i is the first undefined index >= n + a(n), set a(i) = the smallest integer not yet used.
1, 2, 2, 3, 4, 2, 5, 6, 5, 5, 4, 7, 6, 5, 8, 9, 8, 5, 10, 11, 11, 4, 13, 13, 12, 15, 6, 12, 7, 13, 8, 14, 17, 16, 7, 19, 16, 19, 21, 18, 8, 23, 20, 20, 7, 21, 8, 22, 25, 22, 11, 27, 22, 11, 29, 24, 24, 12, 23, 14, 24, 31, 16, 26, 33, 26, 28, 16, 26, 30, 35
Offset: 1
Examples
In the examples, missing terms are denoted by the "_" character and the most recently defined term is denoted as a(n). Starting at n = 1 and a(1) = 1, the next n is therefore 1 + 1 = 2, with a(2) = 2 (the smallest unused positive integer): n 1 2 a(n) 1 2 There are no missing terms, so using n = 2 and a(2) = 2, the next n is 2 + 2 = 4, with a(4) = 3: n 1 2 3 4 a(n) 1 2 _ 3 There is now a single missing term at index 3, so that is the next n. It is 1 step back from the previous n, so a(3) = 3 - 1 = 2. n 1 2 3 4 a(n) 1 2 2 3 There are no missing terms, so using n = 3 and a(3) = 2, the next n is 3 + 2 = 5, with a(5) = 4: n 1 2 3 4 5 a(n) 1 2 2 3 4 There are no missing terms, so using n = 5 and a(5) = 4, the next n is 5 + 4 = 9, with a(9) = 5: n 1 2 3 4 5 6 7 8 9 a(n) 1 2 2 3 4 _ _ _ 5 There are now missing terms, the earliest of which being at index 6, so that is the next n. It is 3 steps back from the previous n, so a(6) = 5 - 3 = 2: n 1 2 3 4 5 6 7 8 9 a(n) 1 2 2 3 4 2 _ _ 5
Links
- Sameer Khan, Table of n, a(n) for n = 1..10000
- Sameer Khan, Scatterplot for 1000 terms
Programs
-
Python
requiredTerms = 100 sequence = [None] * (requiredTerms*2) k,v = 0,1 max = 0 while True: sequence[k] = v if (v > max): max = v u = sequence.index(None) if u >= requiredTerms: break elif u < k: # advance backward, and decrement v by that much too d = k - u (k, v) = (k - d, v - d) else: # skip forward v, then advance to the next unfilled position (k, v) = (sequence.index(None, k + v), max + 1) for result in range(requiredTerms): print(sequence[result])
Comments