Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- #
- # Advent of Code 2024
- # --- Day 3: Mull It Over ---
- # Solution in Perl by Matthias Muth
- #
- use v5.36;
- sub puzzle( $input ) {
- my ( $sum_1, $sum_2 );
- my $do = 1;
- while ( $input =~ / ( do(n't)?\(\) ) | mul\((\d+),(\d+)\) /xg ) {
- if ( $1 ) {
- $do = ! $2;
- next;
- }
- $sum_1 += $3 * $4;
- $sum_2 += $3 * $4 * $do;
- }
- return $sum_1, $sum_2;
- }
- my $input = join "", <>;
- my @answers = puzzle( $input );
- say "Part One answer: ", $answers[0];
- say "Part Two answer: ", $answers[1];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement