Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- no warnings qw(portable);
- use List::AllUtils qw(sum);
- my %mem;
- my $and_mask;
- my $or_mask;
- while (<>) {
- if (m#mask = ([10X]+)#) {
- $or_mask = eval( "0b" . ($1 =~ y/X/0/r) );
- $and_mask = eval( "0b" . ($1 =~ y/X/1/r) );
- } elsif (m#mem\[(\d+)\] = (\d+)#) {
- $mem{$1} = ($2 | $or_mask) & $and_mask;
- }
- }
- print "Part 1: ", sum( values %mem ), "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement