summary refs log tree commit diff homepage
path: root/2023
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2023-12-12 15:01:30 -0500
committerJune McEnroe <june@causal.agency>2023-12-12 15:01:30 -0500
commit123a33bdff2c94388609bea86e888d4afddc3f24 (patch)
tree4067eb52cad2448b53d04365cd5266b97cde57cb /2023
parentSolve day 7 part 2 (diff)
downloadaoc-123a33bdff2c94388609bea86e888d4afddc3f24.tar.gz
aoc-123a33bdff2c94388609bea86e888d4afddc3f24.zip
Solve day 8 part 1
Diffstat (limited to '2023')
-rw-r--r--2023/day08.pl16
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";