From 37e13b2dc557454cbb883723751eecbc830f3305 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Wed, 18 Dec 2024 13:22:50 +0100 Subject: [PATCH] Cleanups of Day 18 --- 2024/35.pl | 3 +-- 2024/36.pl | 13 ++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/2024/35.pl b/2024/35.pl index 79bdc5a..c6b9ca4 100755 --- a/2024/35.pl +++ b/2024/35.pl @@ -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]; } } - diff --git a/2024/36.pl b/2024/36.pl index ec3a0e3..f804979 100755 --- a/2024/36.pl +++ b/2024/36.pl @@ -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; -- 2.47.1