]> www.fi.muni.cz Git - aoc.git/blob - 2023/15.pl
e00311186f5cd5769716794f8bb88d434382fbf2
[aoc.git] / 2023 / 15.pl
1 #!/usr/bin/perl -w
2
3 use v5.38;
4
5 $/ = "\n\n";
6 my %dirs;
7 my @steps = split //, scalar <>;
8 pop @steps;
9 pop @steps;
10 my $l = <>;
11 for (split /\n/, $l) {
12         my @x = /[A-Z]{3}/g;
13         $dirs{$x[0].'L'} = $x[1];
14         $dirs{$x[0].'R'} = $x[2];
15 }
16
17 my %seen;
18 my $now = 'AAA' . $steps[0];
19 my $i = 0;
20 my $n;
21 while ($now !~ /^ZZZ/) {
22         say $now;
23         $i ++;
24         $i = 0 if $i >= @steps;
25         $now = $dirs{$now}.$steps[$i];
26         $n++;
27 }
28 say $n;