OFFSET
0,3
COMMENTS
LINKS
Jan Koornstra, Table of n, a(n) for n = 0..10000
EXAMPLE
For n < 3, n is added to the sequence along with n blanks (denoted by -1): [0, 1, -1, 2, -1, -1]. There are now three blanks in the sequence, hence n = 3 is filled in at the third blank counting from the end of the sequence: [0, 1, 3, 2, -1, -1].
MATHEMATICA
TakeWhile[Nest[Function[{a, n, b}, If[b >= n, ReplacePart[a, Position[a, -1][[-n]] -> n ], Join[a, Prepend[ConstantArray[-1, n], n]]]] @@ {#, Max@ # + 1, Count[#, -1]} &, {0}, 10^3], # > -1 &] (* Michael De Vlieger, Mar 24 2019 *)
PROG
(Python 3)
seq = [0]
for n in range(1, 1387):
num_blanks = seq.count(-1)
if num_blanks >= n: seq[[index for index, value in enumerate(seq) if value == -1][num_blanks - n]] = n
else: seq += [n] + [-1] * n
print(seq[:100])
CROSSREFS
KEYWORD
AUTHOR
Jan Koornstra, Feb 17 2019
STATUS
approved