Generate directions instead of hardcoding.
This commit is contained in:
parent
7a5127db8f
commit
65966ded99
1 changed files with 7 additions and 10 deletions
17
day04.pl
17
day04.pl
|
@ -10,16 +10,13 @@ while (<>) {
|
|||
push @wordgrid, [ split //, $_ ];
|
||||
}
|
||||
|
||||
my @directions = (
|
||||
[[0, 0], [1, 1], [2, 2], [3, 3]],
|
||||
[[0, 0], [-1, 1], [-2, 2], [-3, 3]],
|
||||
[[0, 0], [0, 1], [0, 2], [0, 3]],
|
||||
[[0, 0], [1, 0], [2, 0], [3, 0]],
|
||||
[[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 @directions = ();
|
||||
for my $a (-1 .. 1) {
|
||||
for my $b (-1 .. 1) {
|
||||
next if ($a == 0 && $b == 0);
|
||||
push @directions, [map { [$a * $_, $b * $_ ] } (0 .. 3)];
|
||||
}
|
||||
}
|
||||
|
||||
my @diagonal = ([-1, -1], [0, 0], [1, 1]);
|
||||
my @otherdiagonal = ([1, -1], [0, 0], [-1, 1]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue