diff options
author | Leah Neukirchen <leah@vuxu.org> | 2019-12-07 20:55:21 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2019-12-07 20:55:21 +0100 |
commit | 8fbcd639714c54245c8bbb479d85e75c5aa4f4b0 (patch) | |
tree | 7d5a0ef6e8dfaad66e5fc81cc412e357ffaf233e /day06.pl | |
parent | 2e82083ae7166a0ababfd9b34341fb4fd3dfc0d9 (diff) | |
download | adventofcode2019-8fbcd639714c54245c8bbb479d85e75c5aa4f4b0.tar.gz adventofcode2019-8fbcd639714c54245c8bbb479d85e75c5aa4f4b0.tar.xz adventofcode2019-8fbcd639714c54245c8bbb479d85e75c5aa4f4b0.zip |
day06
Diffstat (limited to 'day06.pl')
-rw-r--r-- | day06.pl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/day06.pl b/day06.pl new file mode 100644 index 0000000..218531b --- /dev/null +++ b/day06.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl -w +use v5.16; + +use File::Slurper 'read_lines'; + +my %orbits; + +for (read_lines("day06")) { + my ($in, $out) = split /\)/; + $orbits{$out} = $in; +} + +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 |