diff options
Diffstat (limited to '2023')
-rw-r--r-- | 2023/day08.pl | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/2023/day08.pl b/2023/day08.pl new file mode 100644 index 0000000..12b41ec --- /dev/null +++ b/2023/day08.pl @@ -0,0 +1,16 @@ +use strict; +use warnings; +my (@dirs, %left, %right); +while (<>) { + chomp; + @dirs = split(//) if /^[LR]+$/; + next unless /([A-Z]{3}) = \(([A-Z]{3}), ([A-Z]{3})\)/; + $left{$1} = $2; + $right{$1} = $3; +} +my ($node, $step) = ("AAA", 0); +while ($node ne "ZZZ") { + my $dir = $dirs[$step++ % @dirs]; + $node = ($dir eq "L" ? $left{$node} : $right{$node}); +} +print $step, "\n"; |