Generate directions instead of hardcoding.

This commit is contained in:
Sebastian Bugge 2024-12-04 09:35:26 +01:00
parent 7a5127db8f
commit 65966ded99
Signed by: kaholaz
GPG key ID: 2EFFEDEE03519691

View file

@ -10,16 +10,13 @@ while (<>) {
push @wordgrid, [ split //, $_ ]; push @wordgrid, [ split //, $_ ];
} }
my @directions = ( my @directions = ();
[[0, 0], [1, 1], [2, 2], [3, 3]], for my $a (-1 .. 1) {
[[0, 0], [-1, 1], [-2, 2], [-3, 3]], for my $b (-1 .. 1) {
[[0, 0], [0, 1], [0, 2], [0, 3]], next if ($a == 0 && $b == 0);
[[0, 0], [1, 0], [2, 0], [3, 0]], push @directions, [map { [$a * $_, $b * $_ ] } (0 .. 3)];
[[0, 0], [-1, -1], [-2, -2], [-3, -3]], }
[[0, 0], [1, -1], [2, -2], [3, -3]], }
[[0, 0], [-1, 0], [-2, 0], [-3, 0]],
[[0, 0], [0, -1], [0, -2], [0, -3]],
);
my @diagonal = ([-1, -1], [0, 0], [1, 1]); my @diagonal = ([-1, -1], [0, 0], [1, 1]);
my @otherdiagonal = ([1, -1], [0, 0], [-1, 1]); my @otherdiagonal = ([1, -1], [0, 0], [-1, 1]);