7 my @steps = split //, $steps;
14 $dirs{$x[0].'L'} = $x[1];
15 $dirs{$x[0].'R'} = $x[2];
21 while ($now !~ /Z$/) {
22 $now = $dirs{$now . ($steps[$i++ % @steps])};
29 ($x, $y) = ($y, $x) if $y > $x;
31 ($x, $y) = ($y, $x % $y);
36 # using LCM is incorrect in general case,
37 # but it works on the actual puzzle input
39 for (uniq grep { /A$/ } map { substr($_, 0, 3) } keys %dirs) {
42 $p *= $steps/gcd($p, $steps);