Advertisement
musifter

AoC 2024, day 25 (Perl)

Dec 25th, 2024
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.50 KB | Source Code | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. no warnings 'portable';         # oct being used on binary nubmer > 32-bits
  6.  
  7. use feature         qw(say);
  8.  
  9. $/ = '';
  10.  
  11. use constant KEY  => 0;
  12. use constant LOCK => 1;
  13.  
  14. my @items;
  15. foreach my $item (map {join('', map {y/.#/01/; $_} split /\n/)} <>) {
  16.     push( $items[ substr($item, 0, 1) ]->@*, oct("0b$item") );
  17. }
  18.  
  19. my $part1 = 0;
  20. foreach my $lock ($items[LOCK]->@*) {
  21.     $part1 += grep {($_ & $lock) == 0} $items[KEY]->@*;
  22. }
  23.  
  24. say "Part 1: $part1";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement