Advertisement
harmth

Untitled

Dec 5th, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.51 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use 5.026;
  3.  
  4. my @chars;
  5. my %scores;
  6.  
  7. @chars = <> =~ /(.)/g;
  8.  
  9. for my $toDel (0, 'a'..'z') {
  10.     my @curChars = grep {!/($toDel|\u$toDel)/} @chars;
  11.  
  12.     for (my $i = 0; $i < @curChars - 1; $i++) {
  13.         if ($curChars[$i] eq ($curChars[$i+1] ^ " ")) {
  14.             splice @curChars, $i, 2;
  15.             $i = $i ? $i - 2 : -1;
  16.         }
  17.     }
  18.  
  19.     say scalar @curChars unless $toDel;
  20.     $scores{$toDel} = scalar @curChars;
  21. }
  22.  
  23. say ((sort { $scores{$a} <=> $scores{$b} } keys %scores)[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement