Jump to content

Determine if a string is collapsible: Difference between revisions

m
no edit summary
(julia example)
mNo edit summary
Line 141:
««« - Hary S Truman »»» (length 17).
</pre>
==== Condensed version: ====
<lang julia>const teststrings = [ "",
""""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 "]
 
collapse(s) = (t = isempty(s) ? "" : s[1]; for c in s if c != t[end] t *= c end; end; t)
 
function testcollapse(arr)
for s in arr
n, t = length(s), collapse(s)
println("«««$s»»» (length $n)\n collapses to:\n«««$t»»» (length $(length(t))).\n")
end
end
 
testcollapse(teststrings)
</lang>
 
=={{header|REXX}}==
4,111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.