Inventory sequence: Difference between revisions

Content added Content deleted
m (Doh. rework example)
Line 27:
 
 
 
=={{header|Python}}==
<syntaxhighlight lang="python">''' rosettacode.org/wiki/Inventory_sequence '''
from collections import Counter
from matplotlib.pyplot import plot
 
def inventory_sequence(terms):
''' From the code by Branicky at oeis.org/A342585 '''
num, alst, inventory = 0, [0], Counter([0])
for n in range(2, terms+1):
c = inventory[num]
num = 0 if c == 0 else num + 1
alst.append(c)
inventory.update([c])
return alst
 
biglist = inventory_sequence(201_790)
thresholds = [1000 * j for j in range(1, 11)]
 
for i, k in enumerate(biglist):
if i < 100:
print(f'{k:<4}', end='\n' if (i + 1) % 20 == 0 else '')
elif k >= thresholds[0]:
print(f'\nFirst element >= {thresholds.pop(0):5}: {k:5} in position {i:6}')
if len(thresholds) == 0:
break
 
plot(biglist[:10_000], linewidth=0.3)
</syntaxhighlight>{{out}}
<pre>
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
 
First element >= 1000: 1001 in position 24255
 
First element >= 2000: 2009 in position 43301
 
First element >= 3000: 3001 in position 61708
 
First element >= 4000: 4003 in position 81456
 
First element >= 5000: 5021 in position 98704
 
First element >= 6000: 6009 in position 121342
 
First element >= 7000: 7035 in position 151756
 
First element >= 8000: 8036 in position 168804
 
First element >= 9000: 9014 in position 184428
 
First element >= 10000: 10007 in position 201788
</pre>
 
=={{header|Raku}}==