Advertisement
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::Util qw(all);
- $/ = '';
- my @locks;
- my @keys;
- foreach my $item (map {[split /\n/]} <>) {
- my @pins;
- foreach my $row (@$item) {
- my @col = split( //, $row );
- foreach my $pin (0 .. 4) {
- $pins[$pin]++ if ($col[$pin] eq '#');
- }
- }
- if ($item->[0] =~ m/^#+$/) {
- push( @locks, \@pins );
- } else {
- push( @keys, \@pins );
- }
- }
- my $part1 = 0;
- foreach my $lock (@locks) {
- foreach my $key (@keys) {
- $part1++ if (all {$key->[$_] + $lock->[$_] <= 7} (0 .. 4));
- }
- }
- say "Part 1: $part1";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement