Determine if a string is collapsible: Difference between revisions
Content added Content deleted
(→{{header|Scala}}: flagged as incorrect (didn't use the five examples as directed).) |
|||
Line 407: | Line 407: | ||
Collapsible: True |
Collapsible: True |
||
Length: 1 <<<A>>> |
Length: 1 <<<A>>> |
||
</pre> |
|||
=={{header|Phix}}== |
|||
There is already a builtin we can abuse for this. The documentation of unique() [added for 0.8.1] states:<br> |
|||
`If "PRESORTED" is specified, but s is not actually sorted, then only adjacent duplicates are removed.` |
|||
<lang Phix>constant tests = {"", |
|||
`"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 "}, |
|||
fmt = """ |
|||
length %2d input: <<<%s>>> |
|||
length %2d output: <<<%s>>> |
|||
""" |
|||
for i=1 to length(tests) do |
|||
string ti = tests[i], ci = unique(ti, "PRESORTED") |
|||
printf(1,fmt,{length(ti),ti,length(ci),ci}) |
|||
end for</lang> |
|||
{{out}} |
|||
<pre> |
|||
length 0 input: <<<>>> |
|||
length 0 output: <<<>>> |
|||
length 72 input: <<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>> |
|||
length 70 output: <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>> |
|||
length 72 input: <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>> |
|||
length 4 output: <<<.178>>> |
|||
length 72 input: <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>> |
|||
length 69 output: <<<I never give 'em hel, I just tel the truth, and they think it's hel. >>> |
|||
length 72 input: <<< --- Harry S Truman >>> |
|||
length 17 output: <<< - Hary S Truman >>> |
|||
</pre> |
</pre> |
||