Goal
Write a program that outputs this list:
0, 1, 1, 0, 2, 2, 2, 0, 3, 2, 4, 1, 1, 0, 4, 4, 4, 1, 4, 0, 5, 5, 4, 1, 6, 2, 1, 0, 6, 7, 5, 1, 6, 3, 3, 1, 0, 7, 9, 5, 3, 6, 4, 4, 2, 0, 8, 9, 6, 4, 9, 4, 5, 2, 1, 3, 0, 9, 10, 7, 5, 10, 6, 6, 3, 1, 4, 2, 0, 10, 11, 8, 6, 11, 6, 9, 3, 2, 5, 3, 2, 0, 11, 11, 10, 8, 11, 7, 9, 4, 3, 6, 4, 5, 0, 12, 11, 10, 9, 13, 8, 10, 4, 4, 7, 6, 6, 1, 1, 0, 13, 13, 10, 9, 15, 8, 12, 5, 5, 8, 7, 6, 2, 3, 0, 14, 13, 11, 10, 15, 10, 13, 6, 6, 8, 9, 7, 2, 5, 1, 2, 0, 15, 14, 13, 10, 15, 11, 15, 7, 7, 9, 10, 8, 2, 6, 2, 5, 0, 16, 14, 15, 10, 15, 12, 16, 9, 8, 11, 12, 9, 4, 6, 3, 7, 2, 0, 17, 14, 16, 11, 16, 12, 17, 10, 9, 13, 13, 10, 5, 8, 4, 7, 4, 2, 0, 18, 14, 17, 11, 18, 13, 17, 11, 10, 13, 15, 12, 6, 10, 5, 8, 4, 4, 2, 0, 19, 14, 18, 11, 20, 14, 18, 11, 11, 13, 16, 15, 6, 11, 7, 9, 5, 4, 4, 1, 1, 0, 20, 16, 18, 11, 22, 15, 19, 12, 11, 14, 16, 18 ...
This is the inventory sequence (OEIS A342585).
Description
The inventory sequence is generated by:
- Setting the index to 0
- Print how many times a value equal to the current index was already printed.
- If the last printed number was 0, go back to 1.
- If the last printed number was not 0, increment the index and go back to 2.
Example Code
Ungolfed Python
#!/usr/bin/env python3
index=0
alreadyPrinted=[] #List of all numbers we already printed. One element per print
while True:
nextNumber = alreadyPrinted.count(index) #How many times did we print a value equal to index?
print(nextNumber,end=' ')
alreadyPrinted.append(nextNumber) #Keep track of all printed numbers
if nextNumber==0:
index=0
print() #Just to add a newline for a nicer looking output, not required
else:
index = index+1
Rules
- Shortest code wins.
- Print at least 250 correct numbers of the sequence, in the correct order from the start of the sequence (obviously).
- Printing more (numbers) after that is allowed, they don't have to be correct.
- If you want it, you can expect a number input for the amount of numbers you have to print. But then the output has to stop at the correct time and you have to support an input of up to 65'000 (all have to be correct).
Start at the beginning
requirement in the link. \$\endgroup\$