X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=2023%2F15.pl;h=83ad39f39b4509b9024b9dd577cce546e5663b71;hb=9df28e43f93ba69cba3f7f56dbb1b77235ad7413;hp=e00311186f5cd5769716794f8bb88d434382fbf2;hpb=156c1de3608eedbe19490679d01b39f89aea53da;p=aoc.git diff --git a/2023/15.pl b/2023/15.pl index e003111..83ad39f 100755 --- a/2023/15.pl +++ b/2023/15.pl @@ -2,27 +2,21 @@ use v5.38; -$/ = "\n\n"; +chomp(my $steps = <>); +my @steps = split //, $steps; + +scalar <>; + my %dirs; -my @steps = split //, scalar <>; -pop @steps; -pop @steps; -my $l = <>; -for (split /\n/, $l) { - my @x = /[A-Z]{3}/g; +while (<>) { + my @x = /\w{3}/g; $dirs{$x[0].'L'} = $x[1]; $dirs{$x[0].'R'} = $x[2]; } -my %seen; -my $now = 'AAA' . $steps[0]; +my $now = 'AAA'; my $i = 0; -my $n; -while ($now !~ /^ZZZ/) { - say $now; - $i ++; - $i = 0 if $i >= @steps; - $now = $dirs{$now}.$steps[$i]; - $n++; +while ($now ne 'ZZZ') { + $now = $dirs{$now . ($steps[$i++ % @steps])}; } -say $n; +say $i;