Factorize string into Lyndon words: Difference between revisions

→‎{{header|RPL}}: version with local variables
m (→‎{{header|RPL}}: was missing)
(→‎{{header|RPL}}: version with local variables)
Line 343:
SWAP OVER - SWAP ROT
'''WHILE''' DUP2 ≥ '''REPEAT'''
'res' s 3 PICK DUP 7 PICK + 1 - SUB STO+
3 PICK +
'''END''' ROT ROT DROP2
Line 357:
1: { "011" "01" "0011" "00101101" "0010110011010011" "00101100110100101101001100101101" "001011001101001011010011001011001101001100101101" "001011001101" "001" }
</pre>
'''Using local variables'''
 
The version below favors local variables to the stack, which makes it a little bit slower - but easier to read.
« DUP SIZE 1 → s n ii
« { }
'''WHILE''' ii n ≤ '''REPEAT'''
ii DUP 1 + → k j
« '''WHILE''' s k DUP SUB s j DUP SUB DUP2 ≤ ii n ≤ AND '''REPEAT'''
< ii k 1 + IFTE 'k' STO
'j' 1 STO+
»
'j' k STO-
'''WHILE''' ii k ≤ '''REPEAT'''
s ii DUP j + 1 - SUB +
'ii' j STO+
'''END'''
»
'''END'''
» » '<span style="color:blue">LYNDON</span>' STO <span style="color:grey">''@ ( "string" → { "f1".."fn" } )''</span>
 
=={{header|Rust}}==
1,150

edits