]> www.fi.muni.cz Git - aoc.git/blobdiff - 2023/15.pl
Day 8: more polished but still incorrect solution
[aoc.git] / 2023 / 15.pl
index e00311186f5cd5769716794f8bb88d434382fbf2..83ad39f39b4509b9024b9dd577cce546e5663b71 100755 (executable)
@@ -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;