Longest common prefix: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Minor tidy) |
(added Easylang) |
||
Line 1,335: | Line 1,335: | ||
foo</pre> |
foo</pre> |
||
=={{header|EasyLang}}== |
|||
<syntaxhighlight> |
|||
func$ lcp list$[] . |
|||
if len list$[] = 0 |
|||
return "" |
|||
. |
|||
shortest$ = list$[1] |
|||
for s$ in list$[] |
|||
if len s$ < len shortest$ |
|||
shortest$ = s$ |
|||
. |
|||
. |
|||
for i to len shortest$ - 1 |
|||
sub$ = substr shortest$ 1 i |
|||
for s$ in list$[] |
|||
if substr s$ 1 i <> sub$ |
|||
return substr shortest$ 1 (i - 1) |
|||
. |
|||
. |
|||
. |
|||
return shortest$ |
|||
. |
|||
print lcp [ "interspecies" "interstellar" "interstate" ] |
|||
print lcp [ "throne" "throne" ] |
|||
print lcp [ "throne" "dungeon" ] |
|||
print lcp [ "throne" "" "throne" ] |
|||
print lcp [ "cheese" ] |
|||
print lcp [ ] |
|||
print lcp [ "foo" "foobar" ] |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
inters |
|||
throne |
|||
cheese |
|||
foo |
|||
</pre> |
|||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |