]> www.fi.muni.cz Git - aoc.git/commitdiff
Cleanups of Day 18
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 18 Dec 2024 12:22:50 +0000 (13:22 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 18 Dec 2024 12:22:50 +0000 (13:22 +0100)
2024/35.pl
2024/36.pl

index 79bdc5abe0c564a9071bc71b6eb3f61646c31232..c6b9ca43764db58d6212f13adbd1b06cab3249f6 100755 (executable)
@@ -8,7 +8,7 @@ my ($xmax, $ymax) = (70,70);
 my %map;
 while (<>) {
        chomp;
-       $map{join(',', split /,/)}++;
+       $map{$_}++;
        # last if $. == 12;
        last if $. == 1024;
 }
@@ -29,4 +29,3 @@ while (@q) {
                push @q, [$cost+1, $nx, $ny];
        }
 }
-
index ec3a0e368e9693beb2a9719694ef9dcd0ce1673f..f8049798a9309b868fd33c9c7900376473efe0cd 100755 (executable)
@@ -7,7 +7,7 @@ my ($xmax, $ymax) = (70,70);
 my %map;
 while (<>) {
        chomp;
-       $map{join(',', split /,/)}++;
+       $map{$_}++;
        # if ($. > 12 && !is_path()) {
        if ($. > 1024 && !is_path()) {
                say $_;
@@ -16,19 +16,18 @@ while (<>) {
 }
 
 sub is_path {
-       my @q = [0, 0, 0];
+       my @q = [0, 0];
        my %seen;
        while (@q) {
-               my ($cost, $x, $y) = @{ shift @q };
-               if ($x == $xmax && $y == $ymax) {
-                       return 1;
-               }
+               my ($x, $y) = @{ shift @q };
+               return 1 if $x == $xmax && $y == $ymax;
+
                for my ($dx, $dy) (-1, 0, 1, 0, 0, -1, 0, 1) {
                        my ($nx, $ny) = ($x+$dx, $y+$dy);
                        next if $map{"$nx,$ny"};
                        next if $seen{"$nx,$ny"}++;
                        next if $nx < 0 || $nx > $xmax || $ny < 0 || $ny > $ymax;
-                       push @q, [$cost+1, $nx, $ny];
+                       push @q, [$nx, $ny];
                }
        }
        return 0;