Longest common prefix: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Miranda) |
(add RPL) |
||
Line 3,298: | Line 3,298: | ||
<pre> |
<pre> |
||
inters |
inters |
||
</pre> |
|||
=={{header|RPL}}== |
|||
≪ DUP SIZE → n |
|||
≪ '''CASE''' |
|||
n NOT '''THEN''' DROP "" '''END''' |
|||
n 1 == '''THEN''' 1 GET '''END''' |
|||
DUP ≪ SIZE ≫ DOLIST ≪ MIN ≫ STREAM <span style="color:grey">@ get the size of the smallest string</span> |
|||
'''IF''' DUP NOT '''THEN''' DROP2 "" '''ELSE''' |
|||
1 OVER '''FOR''' j |
|||
OVER 1 ≪ 1 j SUB ≫ DOLIST |
|||
'''IF''' ≪ == ≫ DOSUBS 1 + ΠLIST NOT '''THEN''' |
|||
j 1 - SWAP ‘j’ STO '''END''' |
|||
'''NEXT''' |
|||
SWAP 1 GET 1 ROT SUB |
|||
'''END END''' |
|||
≫ ≫ '<span style="color:blue">LCP</span>' STO |
|||
{ { "interspecies" "interstellar" "interstate" } { "throne" "throne" } { "throne" "dungeon" }{ "throne" "" "throne" } { "cheese" } { "" } { } { "prefix" "suffix" } { "foo" "foobar" } } ≪ <span style="color:blue">LCP</span> ≫ DOLIST |
|||
{{out}} |
|||
<pre> |
|||
1: { "inters" "throne" "" "" "cheese" "" "" "" "foo" } |
|||
</pre> |
</pre> |
||