Determine if a string is collapsible: Difference between revisions

m
→‎{{header|Perl 6}}: Edit to answer more accurately what the task description is asking for.
(→‎{{header|Perl 6}}: Add a Perl 6 example)
m (→‎{{header|Perl 6}}: Edit to answer more accurately what the task description is asking for.)
Line 231:
=={{header|Perl 6}}==
{{works with|Rakudo|2019.07.1}}
Technically, the task is asking for a boolean. "Determine if a string is collapsible" is answerable with a True/False, so return a boolean as well.
 
<lang perl6>map {
my $squish = .comb.squish.join;
printf "\nLength: %2d <<<%s>>>\nCollapsible: %s\nLength: %2d <<<%s>>>\n", .chars, $_, $squish.chars, $squish
.chars, $_, .chars != $squish.chars, $squish.chars, $squish
}, lines
 
qq:to/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
AАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑAАΑ
STRINGS</lang>
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
STRINGS</lang>
</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 <<<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: 72 <<<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>
 
10,343

edits