musifter

AoC 2025 day 7 part 1 (Perl)

Dec 6th, 2025 (edited)
32
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/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use feature         qw(say);
  7. use List::AllUtils  qw(indexes);
  8.  
  9. my @input = map { chomp; [split //] } <>;
  10.  
  11. my $part1 = 0;
  12. my %beams = map { $_ => 1 } indexes { $_ eq 'S' } @{shift @input};
  13.  
  14. while (my $row = shift @input) {
  15.     my @splitters = indexes { $_ eq '^' } @$row;
  16.     next if (!@splitters);
  17.  
  18.     my @splits = grep { exists $beams{$_} } @splitters;
  19.     $part1 += @splits;
  20.  
  21.     foreach my $split (@splits) {
  22.         delete $beams{$split};
  23.         $beams{$split-1}++;
  24.         $beams{$split+1}++;
  25.     }
  26. }
  27.  
  28. say "Part 1: $part1";
Advertisement
Add Comment
Please, Sign In to add comment