Determine if a string is collapsible: Difference between revisions

add sed
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(add sed)
Line 3,482:
COLLAPSED : length = 7, string = «««ardvark»»»
This string IS collapsible !</pre>
 
=={{header|sed}}==
Since sed has no native support for arithmetic, line length counting is omitted in this solution for simplicity:
<syntaxhighlight lang="sed">h
s/.*/<<<&>>>/
x
s/\(.\)\1*/\1/g
s/.*/<<<&>>>/
H
s/.*//
G</syntaxhighlight>
Test:
<pre>
printf '%s\n' \
'' \
'"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ' \
'..1111111111111111111111111111111111111111111111111111111111111117777888' \
"I never give 'em hell, I just tell the truth, and they think it's hell. " \
' --- Harry S Truman ' \
| sed -f collapse.sed
</pre>
{{out}}
<pre>
 
<<<>>>
<<<>>>
 
<<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>>
<<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>>
 
<<<..1111111111111111111111111111111111111111111111111111111111111117777888>>>
<<<.178>>>
 
<<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>
<<<I never give 'em hel, I just tel the truth, and they think it's hel. >>>
 
<<< --- Harry S Truman >>>
<<< - Hary S Truman >>>
</pre>
 
=={{header|Sidef}}==
559

edits