Advertisement
musifter

AoC day 16 (pt1), Perl

Dec 16th, 2020
1,440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.36 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use List::AllUtils  qw(sum);
  7.  
  8. $/ = '';
  9.  
  10. my @valid;
  11.  
  12. $_ = <>;    # read ranges:
  13. foreach my $range (map { s#-#..#r } m#\d+-\d+#g) {
  14.     $valid[ $_ ] = 1  foreach (eval( $range ));
  15. }
  16.  
  17. $_ = <>;    # skip my ticket
  18. $_ = <>;    # check nearby tickets:
  19.  
  20. print "Part 1: ", sum( grep { !$valid[$_] } (m#\d+#g) ), "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement