Add day 3.
This commit is contained in:
parent
6706514760
commit
e114e13fea
1 changed files with 32 additions and 0 deletions
32
day03.pl
Normal file
32
day03.pl
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
my $sum = 0;
|
||||||
|
my $enable = 1;
|
||||||
|
|
||||||
|
## Part 1
|
||||||
|
#while (<>) {
|
||||||
|
# while (/mul\((\d+),(\d+)\)/g) {
|
||||||
|
# $sum += $1 * $2;
|
||||||
|
# }
|
||||||
|
#}
|
||||||
|
#print $sum;
|
||||||
|
|
||||||
|
## Part 2
|
||||||
|
while (<>) {
|
||||||
|
while (/do\(\)|don't\(\)|mul\((\d+),(\d+)\)/g) {
|
||||||
|
if ($& eq 'do()') {
|
||||||
|
$enable = 1;
|
||||||
|
next;
|
||||||
|
} elsif ($& eq "don't()") {
|
||||||
|
$enable = 0;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sum += $1 * $2 if ($enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print $sum;
|
Loading…
Add table
Add a link
Reference in a new issue