Inventory sequence: Difference between revisions

→‎{{header|RPL}}: improved code
(added RPL)
(→‎{{header|RPL}}: improved code)
Line 686:
=={{header|RPL}}==
For efficiency reasons, two different programs are needed to generate the sequence or search for the first high value.
« → max
« { 0 1 1 0 } <span style="color:grey">@ need to start with a non-null cycle to have ∑LIST work</span>
'''WHILE''' DUP2DUP SIZE >max < '''REPEAT'''
1 CF 0
0 max '''FOR''' j
'''DO''' DUP2 LASTARG AND DUP 1 « j == » DOLIST ∑LIST <span style="color:grey">@ count occurrences in the list</span>
'''IF''' DUP NOT '''THEN''' 1max 'j' SFSTO '''END'''
ROT SWAP + SWAP
1 +
'''UNTIL''' 1 FS? '''ENDNEXT'''
DROP'''END'''
1 CFmax 0SUB
'''END'''
» '<span style="color:blue">INVT</span>' STO <span style="color:grey">@ ''( n → { a(1)..a(n)} )''</span>
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
Line 710 ⟶ 709:
'''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>
1,151

edits