Advertisement
muthm

AoC [2024 Day 3] [Language: Perl]

Dec 3rd, 2024 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.59 KB | Source Code | 0 0
  1. #!/usr/bin/env perl
  2. #
  3. #       Advent of Code 2024
  4. #       --- Day 3: Mull It Over ---
  5. #       Solution in Perl by Matthias Muth
  6. #
  7.  
  8. use v5.36;
  9.  
  10. sub puzzle( $input ) {
  11.     my ( $sum_1, $sum_2 );
  12.     my $do = 1;
  13.     while ( $input =~ / ( do(n't)?\(\) ) | mul\((\d+),(\d+)\) /xg ) {
  14.         if ( $1 ) {
  15.             $do = ! $2;
  16.             next;
  17.         }
  18.         $sum_1 += $3 * $4;
  19.         $sum_2 += $3 * $4 * $do;
  20.     }
  21.     return $sum_1, $sum_2;
  22. }
  23.  
  24. my $input = join "", <>;
  25. my @answers = puzzle( $input );
  26. say "Part One answer: ", $answers[0];
  27. say "Part Two answer: ", $answers[1];
Tags: AoC2024
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement