blob: 9c942746d321fb7439f6d9f3f57d5d119530f8fe (
plain) (
blame)
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
|
#!/usr/bin/perl -w
use v5.16;
use File::Slurper 'read_lines';
my %orbits = map { reverse split /\)/ } read_lines("day06");
my $p1 = 0;
for (keys %orbits) {
while ($_ ne "COM") {
$p1++;
$_ = $orbits{$_};
}
}
say $p1; # 147223
my (@path1, @path2);
$_ = "YOU"; push @path1, $_ = $orbits{$_} while ($_ ne "COM");
$_ = "SAN"; push @path2, $_ = $orbits{$_} while ($_ ne "COM");
while ($path1[-1] eq $path2[-1]) {
pop @path1;
pop @path2;
}
say @path1 + @path2; # 340
|