5 use experimental 'multidimensional';
7 my %seen = ("0,0" => 1);
9 push @knots, [0, 0] for 1 .. 10;
11 sub follow ($x, $y, $tx, $ty) {
15 } elsif ($y == $ty + 2) {
21 } elsif ($x == $tx + 2) {
24 } elsif ($x == $tx - 2) {
31 } elsif ($x == $tx + 2) {
38 } elsif ($y == $ty - 2) {
45 } elsif ($y == $ty + 2) {
57 my ($dir, $len) = /^(.) (\d+)/;
62 } elsif ($dir eq 'D') {
64 } elsif ($dir eq 'L') {
66 } elsif ($dir eq 'R') {
71 ($knots[$_][0], $knots[$_][1]) = follow(
77 $seen{"$knots[-1][0],$knots[-1][1]"}++;
81 say scalar keys %seen;