From 123a33bdff2c94388609bea86e888d4afddc3f24 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 12 Dec 2023 15:01:30 -0500 Subject: Solve day 8 part 1 --- 2023/day08.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2023/day08.pl (limited to '2023') 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"; -- cgit 1.4.1