copy pasting the rules from last year’s thread:

Rules: no spoilers.

The other rules are made up aswe go along.

Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.

You are viewing a single thread.
View all comments View context
1 point

Yay, day 3 with Regexp magic.

Day 3
open(FH, '<', $ARGV[0]) or die $!;
my $sum = 0;
my $sum2 = 0;

my $enabled = 1;

while (<FH>) {
    while ($_ =~ /(?:mul\((\d{1,3}),(\d{1,3})\)|(do)\(\)|(don\'t)\(\))/g) {
        $enabled = 1 if $3;
        $enabled = 0 if $4;
        $sum += $1 * $2 if $1 && $2;
        $sum2 += $1 * $2 if $enabled && $1 && $2;
    }
}

close(FH);

print "Part 1: $sum\n";
print "Part 2: $sum2\n";
permalink
report
parent
reply

NotAwfulTech

!notawfultech@awful.systems

Create post

a community for posting cool tech news you don’t want to sneer at

non-awfulness of tech is not required or else we wouldn’t have any posts

Community stats

  • 345

    Monthly active users

  • 55

    Posts

  • 151

    Comments

Community moderators