Longest common prefix: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) No edit summary |
|||
Line 663: | Line 663: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
<lang rebol>lcp: function [lst][ |
|||
{{trans|D}} |
|||
<lang arturo>lcp: @(list){ |
|||
ret: "" |
ret: "" |
||
idx: 0 |
idx: 0 |
||
while [true] [ |
|||
thisLetter: "" |
thisLetter: "" |
||
loop |
loop lst 'word [ |
||
if idx= |
if idx=size word -> return ret |
||
if thisLetter="" -> thisLetter: |
if thisLetter="" -> thisLetter: get split word idx |
||
if thisLetter |
if thisLetter<>get split word idx -> return ret |
||
⚫ | |||
ret: ret ++ thisLetter |
|||
idx: idx + 1 |
|||
] |
|||
] |
|||
⚫ | |||
} |
|||
print lcp ["interspecies" "interstellar" "interstate"] |
|||
print |
print lcp ["throne" "throne"] |
||
print |
print lcp ["throne" "dungeon"] |
||
print |
print lcp ["throne" "" "throne"] |
||
print |
print lcp ["cheese"] |
||
print |
print lcp [""] |
||
print |
print lcp ["prefix" "suffix"] |
||
print |
print lcp ["foo" "foobar"]</lang> |
||
print [lcp #("foo" "foobar")]</lang> |
|||
{{out}} |
{{out}} |
||
Line 702: | Line 698: | ||
foo</pre> |
foo</pre> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |