diff options
author | June McEnroe <june@causal.agency> | 2023-12-12 15:01:30 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2023-12-12 15:01:30 -0500 |
commit | 123a33bdff2c94388609bea86e888d4afddc3f24 (patch) | |
tree | 4067eb52cad2448b53d04365cd5266b97cde57cb /2023 | |
parent | Solve day 7 part 2 (diff) | |
download | aoc-123a33bdff2c94388609bea86e888d4afddc3f24.tar.gz aoc-123a33bdff2c94388609bea86e888d4afddc3f24.zip |
Solve day 8 part 1
Diffstat (limited to '')
-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"; |