Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use 5.026;
- my @chars;
- my %scores;
- @chars = <> =~ /(.)/g;
- for my $toDel (0, 'a'..'z') {
- my @curChars = grep {!/($toDel|\u$toDel)/} @chars;
- for (my $i = 0; $i < @curChars - 1; $i++) {
- if ($curChars[$i] eq ($curChars[$i+1] ^ " ")) {
- splice @curChars, $i, 2;
- $i = $i ? $i - 2 : -1;
- }
- }
- say scalar @curChars unless $toDel;
- $scores{$toDel} = scalar @curChars;
- }
- say ((sort { $scores{$a} <=> $scores{$b} } keys %scores)[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement