Determine if a string is collapsible: Difference between revisions

no edit summary
(Add BCPL)
No edit summary
Line 1,757:
old: 72 <<< --- Harry S Truman >>>
new: 17 <<< - Hary S Truman >>></pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>ClearAll[StringCollapse]
StringCollapse[s_String] := FixedPoint[StringReplace[y_ ~~ y_ :> y], s]
strings = {"",
"\"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 "};
Do[
Print["«««" <> s <> "»»»"];
Print["Length = ", StringLength[s]];
Print["«««" <> StringCollapse[s] <> "»»»"];
Print["Length = ", StringLength[StringCollapse[s]]]
,
{s, strings}
]</lang>
{{out}}
<pre>«««»»»
Length = 0
«««»»»
Length = 0
«««"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln »»»
Length = 72
«««"If I were two-faced, would I be wearing this one?" - Abraham Lincoln »»»
Length = 70
«««..1111111111111111111111111111111111111111111111111111111111111117777888»»»
Length = 72
«««.178»»»
Length = 4
«««I never give 'em hell, I just tell the truth, and they think it's hell. »»»
Length = 72
«««I never give 'em hel, I just tel the truth, and they think it's hel. »»»
Length = 69
««« --- Harry S Truman »»»
Length = 72
««« - Hary S Truman »»»
Length = 17</pre>
 
=={{header|MATLAB}} / {{header|Octave}}==
1,111

edits