Advertisement
musifter

AoC 2021 day 24, Perl exploration

Dec 24th, 2021
2,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.57 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use List::AllUtils  qw(indexes pairwise);
  7.  
  8. my @Code = map { chomp; $_ } <>;
  9. my @Blocks = indexes { $_ =~ m#inp# } @Code;
  10.  
  11. my @Fixed = @Code[0 .. 17];
  12.  
  13. foreach my $bi (@Blocks) {
  14.     foreach my $l (0 .. 17) {
  15.         if ($Code[$bi + $l] ne $Fixed[$l]) {
  16.             $Fixed[$l] = join( ' ', pairwise { ($a eq $b) ? $a : '???' }
  17.                                         @{[split(/ /, $Fixed[$l])]},
  18.                                         @{[split(/ /, $Code[$bi + $l])]});
  19.         }
  20.     }
  21. }
  22.  
  23. print join( "\n", @Fixed );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement