Advertisement
musifter

AoC 2021 day 3, part 1 (Perl)

Dec 3rd, 2021
1,678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.33 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use List::AllUtils qw(pairwise);
  7.  
  8. my @counts = (0) x 12;
  9. while (<>) {
  10.     chomp;
  11.     @counts = pairwise {$a + $b} @counts, @{[split //]};
  12. }
  13.  
  14. my $half = $. / 2;
  15. my $gamma = oct("0b" . join( '', map {int($_ > $half)} @counts ));
  16.  
  17. print "Part 1: ", $gamma * ($gamma ^ 0xFFF), "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement