Determine if a string has all the same characters: Difference between revisions
Content deleted Content added
m →{{header|zkl}}: change wording |
Thundergnat (talk | contribs) →{{header|Perl 6}}: Simplify, avoid using grammar engine unnecessarily |
||
Line 217: | Line 217: | ||
<lang perl6> -> $str { |
<lang perl6> -> $str { |
||
my $i = 0; |
|||
print "\n{$str.perl} (length: {$str.chars}), has "; |
print "\n{$str.perl} (length: {$str.chars}), has "; |
||
my $match = $str.match( / (.) /, :g ); |
|||
my %m; |
my %m; |
||
%m{$_}.push: ++$i for $str.comb; |
|||
if %m > 1 { |
if %m > 1 { |
||
say "different characters:"; |
say "different characters:"; |
||
say "'{.key}' ({.key.uninames}; hex ordinal: {(.key.ords).fmt: "0x%X"})" ~ |
say "'{.key}' ({.key.uninames}; hex ordinal: {(.key.ords).fmt: "0x%X"})" ~ |
||
" in positions: {.value |
" in positions: {.value.join: ', '}" for %m.sort( *.value[0] ); |
||
} else { |
} else { |
||
say "the same character in all positions." |
say "the same character in all positions." |