Inventory sequence: Difference between revisions

added RPL
(→‎{{header|Mathematica}}: image position -> center)
(added RPL)
Line 684:
[[File:Inventory-raku.png|400px|thumb|left|]]
<br clear=all>
=={{header|RPL}}==
For efficiency reasons, two different programs are needed to generate the sequence or search for the first high value.
« { 0 1 1 0 } <span style="color:grey">@ need to start with a non-null cycle to have ∑LIST work</span>
'''WHILE''' DUP2 SIZE > '''REPEAT'''
1 CF 0
'''DO''' DUP2 ≤ LASTARG ≥ AND ∑LIST <span style="color:grey">@ count occurrences in the list</span>
'''IF''' DUP NOT '''THEN''' 1 SF '''END'''
ROT SWAP + SWAP
1 +
'''UNTIL''' 1 FS? '''END'''
DROP
'''END'''
1 ROT SUB
» '<span style="color:blue">INVT</span>' STO <span style="color:grey">@ ''( n → { a(1)..a(n)} )''</span>
« DUP 1 + { } + 0 CON -1 → max counts j
« 2 CF 1
'''DO''' 'counts' 'j' INCR 1 +
'''IFERR''' GET THEN DROP2 0 '''END'''
'''IF''' DUP NOT THEN -1 'j' STO '''END'''
'''IF''' DUP max > '''THEN'''
"element" →TAG SWAP "position" →TAG 2 SF
'''ELSE'''
'counts' SWAP 1 + DUP2 GET 1 + PUT 1 +
'''END'''
'''UNTIL''' 2 FS? '''END'''
» » '<span style="color:blue">INVT1ST</span>' STO <span style="color:grey">@ ''( n → 1st_value_>_n pos )''</span>
 
100 <span style="color:blue">INVT</span>
1000 <span style="color:blue">INVT1ST</span>
{{out}}
<pre>
3: { 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 }
2: element: 1001
1: position: 24256
</pre>
 
=={{header|Ruby}}==
Not actually counting but keeping count in a hash:
1,151

edits