Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- my $part2 = 0;
- my $do = 1;
- foreach my $line (<>) {
- while ($line =~ m#(do(n't)?\(\)|mul\(\d{1,3},\d{1,3}\))#g) {
- if ($1 eq "do()") {
- $do = 1;
- } elsif ($1 eq "don't()") {
- $do = 0;
- } elsif ($do) {
- $1 =~ m#(\d+),(\d+)#;
- $part2 += $1 * $2;
- }
- }
- }
- say "Part 2: ", $part2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement