Determine if a string is collapsible: Difference between revisions
Determine if a string is collapsible (view source)
Revision as of 17:28, 14 March 2020
, 4 years ago→{{header|Factor}}
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
|||
Line 468:
result string: <<< - Hary S Truman >>>, length = 17
</pre>
=={{header|D}}==
<lang d>import std.stdio;
void collapsible(string s) {
writeln("old: <<<", s, ">>>, length = ", s.length);
write("new: <<<");
char last = '\0';
int len = 0;
foreach (c; s) {
if (c != last) {
write(c);
len++;
}
last = c;
}
writeln(">>>, length = ", len);
writeln;
}
void main() {
collapsible(``);
collapsible(`"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln `);
collapsible(`..1111111111111111111111111111111111111111111111111111111111111117777888`);
collapsible(`I never give 'em hell, I just tell the truth, and they think it's hell. `);
collapsible(` --- Harry S Truman `);
}</lang>
{{out}}
<pre>old: <<<>>>, length = 0
new: <<<>>>, length = 0
old: <<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>>, length = 72
new: <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>>, length = 70
old: <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>>, length = 72
new: <<<.178>>>, length = 4
old: <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>, length = 72
new: <<<I never give 'em hel, I just tel the truth, and they think it's hel. >>>, length = 69
old: <<< --- Harry S Truman >>>, length = 72
new: <<< - Hary S Truman >>>, length = 17</pre>
=={{header|Factor}}==
|