11 for my $step (split /,/, $desc) {
12 my ($dir, $dist) = $step =~ /([A-Z])(\d+)/;
14 ($dx, $dy) = (1, 0) if $dir eq 'R';
15 ($dx, $dy) = (0, 1) if $dir eq 'D';
16 ($dx, $dy) = (0, -1) if $dir eq 'U';
17 ($dx, $dy) = (-1, 0) if $dir eq 'L';
19 $x += $dx; $y += $dy; ++$l;
22 say "$step -> $x, $y ($rv{$x,$y})";
27 my $p1 = walk(scalar <>);
28 my $p2 = walk(scalar <>);
31 for my $pos (keys %$p1) {
33 next if $pos eq '0,0';
34 my $d = $p1->{$pos}+$p2->{$pos};
35 say "Intersection at $pos dist $d";
36 $dist = $d if !$dist || $dist > $d;