Factorize string into Lyndon words: Difference between revisions
Content deleted Content added
julia example |
added RPL |
||
Line 328: | Line 328: | ||
['011', '01', '0011', '00101101', '0010110011010011', '00101100110100101101001100101101', '001011001101001011010011001011001101001100101101', '001011001101', '001'] |
['011', '01', '0011', '00101101', '0010110011010011', '00101100110100101101001100101101', '001011001101001011010011001011001101001100101101', '001011001101', '001'] |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Rust}}== |
|||
Based on Duval's algorithm. |
|||
<code>THUEM</code> is defined at [[Thue-Morse#RPL|Thue-Morse]]. |
|||
« DUP SIZE { } → s n res |
|||
« 1 |
|||
'''WHILE''' DUP n ≤ '''REPEAT''' |
|||
DUP 1 + OVER |
|||
'''WHILE''' s OVER DUP SUB s 4 PICK DUP SUB DUP2 ≤ 5 PICK n ≤ AND '''REPEAT''' |
|||
'''IF''' < '''THEN''' DROP OVER '''ELSE''' 1 + '''END''' |
|||
SWAP 1 + SWAP |
|||
'''END''' DROP2 |
|||
SWAP OVER - SWAP ROT |
|||
'''WHILE''' DUP2 ≥ '''REPEAT''' |
|||
'res' s 3 PICK DUP 7 PICK + SUB STO+ |
|||
3 PICK + |
|||
'''END''' ROT ROT DROP2 |
|||
'''END''' |
|||
DROP res |
|||
» » '<span style="color:blue">LYNDON</span>' STO <span style="color:grey">''@ ( "string" → { "f1".."fn" } )''</span> |
|||
« 2 7 ^ <span style="color:blue">THUEM</span> « →STR + » STREAM |
|||
<span style="color:blue">LYNDON</span> |
|||
» '<span style="color:blue">TASK</span>' STO |
|||
{{out}} |
|||
<pre> |
|||
1: { "011" "01" "0011" "00101101" "0010110011010011" "00101100110100101101001100101101" "001011001101001011010011001011001101001100101101" "001011001101" "001" } |
|||
</pre> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Line 372: | Line 400: | ||
["011", "01", "0011", "00101101", "0010110011010011", "00101100110100101101001100101101", "001011001101001011010011001011001101001100101101", "001011001101", "001"] |
["011", "01", "0011", "00101101", "0010110011010011", "00101100110100101101001100101101", "001011001101001011010011001011001101001100101101", "001011001101", "001"] |
||
</pre> |
</pre> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |