Jump to content

Longest common prefix: Difference between revisions

m
→‎version 3: added whitespace.
m (→‎version 2: added whitespace.)
m (→‎version 3: added whitespace.)
Line 2,847:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
LCP: @= arg(1); m= length(@); #=arg(); say copies('▒', 60)
say '────────────── number of strings specified:' #
do i=1 for #; say '────────────── string' i":" showNull(arg(i))
end /*i*/
 
do j=2 to #; x= arg(j); t= compare(@, x) /*compare to next.*/
if t==1 | x=='' then do; @=; leave; end /*mismatch of strs*/
if t==0 & @==x then t= length(@) + 1 /*both are equal. */
if t>=m then iterate /*not longest str.*/
m= t - 1; @= left(@, max(0, m)) ) /*define maximum. */
end /*j*/
return ' longest common prefix=' shownull(@ ) /*return answer. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showNull: procedure; parse arg z; if z=='' then z= "«null»"; return z</lang>
'''{{out|output''' |text=&nbsp; when using the default inputs:}}
<pre>
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
Cookies help us deliver our services. By using our services, you agree to our use of cookies.