Determine if a string is collapsible: Difference between revisions
Determine if a string is collapsible (view source)
Revision as of 15:10, 19 November 2019
, 4 years agoAdded Perl example
m (→{{header|zkl}}: tweak) |
SqrtNegInf (talk | contribs) (Added Perl example) |
||
Line 289:
end
</lang>
=={{header|Perl}}==
<lang perl>use strict;
use warnings;
use utf8;
binmode STDOUT, ":utf8";
my @lines = split "\n", <<~'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
The American people have a right to know if their president is a crook.
--- Richard Nixon
AАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑ
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
STRINGS
for (@lines) {
my $squish = s/(.)\1+/$1/gr;
printf "\nLength: %2d <<<%s>>>\nCollapsible: %s\nLength: %2d <<<%s>>>",
length($_), $_, $_ ne $squish ? 'True' : 'False', length($squish), $squish
}</lang>
{{out}}
<pre>Length: 0 <<<>>>
Collapsible: False
Length: 0 <<<>>>
Length: 72 <<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>>
Collapsible: True
Length: 70 <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>>
Length: 72 <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>>
Collapsible: True
Length: 4 <<<.178>>>
Length: 72 <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>
Collapsible: True
Length: 69 <<<I never give 'em hel, I just tel the truth, and they think it's hel. >>>
Length: 72 <<< --- Harry S Truman >>>
Collapsible: True
Length: 17 <<< - Hary S Truman >>>
Length: 72 <<<The American people have a right to know if their president is a crook. >>>
Collapsible: True
Length: 71 <<<The American people have a right to know if their president is a crok. >>>
Length: 72 <<< --- Richard Nixon >>>
Collapsible: True
Length: 17 <<< - Richard Nixon >>>
Length: 120 <<<AАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑ>>>
Collapsible: False
Length: 120 <<<AАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑ>>>
Length: 72 <<<AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA>>>
Collapsible: True
Length: 1 <<<A>>></pre>
=={{header|Perl 6}}==
|