-
Notifications
You must be signed in to change notification settings - Fork 0
/
day4.pl
52 lines (45 loc) · 730 Bytes
/
day4.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env perl
## no critic
use strict;
use warnings;
use List::Util qw(sum);
use DDP;
my $i = 0;
my @p;
my @k;
my $K;
while (<STDIN>) {
my @a = split( /\|/, ( split( /:/, $_, 2 ) )[1], 2 );
my @t = $a[0] =~ /(\d+)/gx;
my @f = $a[1] =~ /(\d+)/gx;
my $j = 0;
foreach my $a (@t) {
foreach my $b (@f) {
$j++ if $a == $b;
}
}
if ($j < 1) {
$p[$i] = 0;
} else {
$p[$i] = $j;
my $l = 2**( $j - 1 );
$K += $l;
}
$i++;
}
$i--;
unshift @k, 0..$i;
my %h;
my $t;
while (defined(my $j = shift @k)) {
next if $j > $i;
if (my $l = $p[$j]) {
for (1 .. $l) {
my $o = $j + $_;
push @k, $o;
}
}
$t++;
}
print "PART 1: $K\n";
print "PART 2: $t\n";