Determine if a string is collapsible: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add a Perl 6 example) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Edit to answer more accurately what the task description is asking for.) |
||
Line 231: | Line 231: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo|2019.07.1}} |
{{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 { |
<lang perl6>map { |
||
my $squish = .comb.squish.join; |
my $squish = .comb.squish.join; |
||
printf "\nLength: %2d <<<%s>>>\nLength: %2d <<<%s>>>\n", |
printf "\nLength: %2d <<<%s>>>\nCollapsible: %s\nLength: %2d <<<%s>>>\n", |
||
.chars, $_, .chars != $squish.chars, $squish.chars, $squish |
|||
}, lines |
}, lines |
||
qq:to/STRINGS/; |
qq:to/STRINGS/; |
||
"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln |
"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln |
||
..1111111111111111111111111111111111111111111111111111111111111117777888 |
..1111111111111111111111111111111111111111111111111111111111111117777888 |
||
I never give 'em hell, I just tell the truth, and they think it's hell. |
I never give 'em hell, I just tell the truth, and they think it's hell. |
||
--- Harry S Truman |
--- 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АΑ |
|||
⚫ | |||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
|||
⚫ | |||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>Length: 0 <<<>>> |
<pre>Length: 0 <<<>>> |
||
Collapsible: False |
|||
Length: 0 <<<>>> |
Length: 0 <<<>>> |
||
Length: 72 <<<"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 >>> |
||
Collapsible: True |
|||
Length: 70 <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>> |
Length: 70 <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>> |
||
Length: 72 <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>> |
Length: 72 <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>> |
||
Collapsible: True |
|||
Length: 4 <<<.178>>> |
Length: 4 <<<.178>>> |
||
Length: 72 <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>> |
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: 69 <<<I never give 'em hel, I just tel the truth, and they think it's hel. >>> |
||
Length: 72 <<< --- Harry S Truman >>> |
Length: 72 <<< --- Harry S Truman >>> |
||
Collapsible: True |
|||
Length: 17 <<< - Hary S Truman >>> |
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> |
</pre> |
||