Inventory sequence: Difference between revisions

(Created Nim solution.)
Line 488:
[[File:Inventory-raku.png|400px|thumb|left|]]
<br clear=all>
=={{header|Ruby}}==
Not actually counting but keeping count in a hash:
<syntaxhighlight lang="ruby" line>n = 0
counter = Hash.new(0)
inventory = loop.lazy.map do
c = counter[n]
counter[c] += 1
c == 0 ? n = 0 : n += 1
c
end
inventory.first(100).each_slice(10){|s| puts "%4d"*s.size % s}
puts
 
(1000..10000).step(1000).each do |t|
counter.clear
puts "First element >= #{t} : %d index %d" % inventory.with_index.detect{|e,i| e > t}
end
</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 index 24255
First element >= 2000 : 2009 index 43301
First element >= 3000 : 3001 index 61708
First element >= 4000 : 4003 index 81456
First element >= 5000 : 5021 index 98704
First element >= 6000 : 6009 index 121342
First element >= 7000 : 7035 index 151756
First element >= 8000 : 8036 index 168804
First element >= 9000 : 9014 index 184428
First element >= 10000 : 10007 index 201788
</pre>
 
=={{header|Wren}}==
{{libheader|DOME}}
1,149

edits