Determine if a string is collapsible: Difference between revisions
Content deleted Content added
mNo edit summary |
|||
Line 142:
</pre>
==== Condensed version: ====
<lang julia>const teststrings = [
""""If I were two-faced, would I be wearing this one?" --- Abraham Lincoln """,
"..1111111111111111111111111111111111111111111111111111111111111117777888",
Line 150 ⟶ 151:
collapse(s) = (t = isempty(s) ? "" : s[1]; for c in s if c != t[end] t *= c end; end; t)
▲ n, t = length(s), collapse(s)
▲ println("«««$s»»» (length $n)\n collapses to:\n«««$t»»» (length $(length(t))).\n")
▲ end
end
▲testcollapse(teststrings)
</lang>
|