Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- use List::AllUtils qw(indexes);
- my @input = map { chomp; [split //] } <>;
- my $part1 = 0;
- my %beams = map { $_ => 1 } indexes { $_ eq 'S' } @{shift @input};
- while (my $row = shift @input) {
- my @splitters = indexes { $_ eq '^' } @$row;
- next if (!@splitters);
- my @splits = grep { exists $beams{$_} } @splitters;
- $part1 += @splits;
- foreach my $split (@splits) {
- delete $beams{$split};
- $beams{$split-1}++;
- $beams{$split+1}++;
- }
- }
- say "Part 1: $part1";
Advertisement
Add Comment
Please, Sign In to add comment