From 8c035a6f79767d1e9f2f2290bbf27de2e1485793 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Fri, 25 Nov 2022 09:08:47 +0100 Subject: [PATCH] Fixup for 2018 day 15/2 --- 2018/30.pl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/2018/30.pl b/2018/30.pl index 61e60e5..663fa08 100755 --- a/2018/30.pl +++ b/2018/30.pl @@ -43,7 +43,7 @@ sub print_map { print "\n"; } for my $unit (grep { $_->[3] } reading_sort(@units)) { - say "$unit->[2] at $unit->[0],$unit->[1] ($unit->[3])" + say "# $unit->[2] at ($unit->[1]+$unit->[0]j) $unit->[3]" } } @@ -107,7 +107,7 @@ sub dump_path($path) { sub move($unit) { my %target_sq; - for my $enemy (grep { $_->[2] ne $unit->[2] } @units) { + for my $enemy (grep { $_->[2] ne $unit->[2] && $_->[3] > 0 } @units) { for my $sq (neigh_squares($enemy, '.')) { if (!$target_sq{$sq->[0],$sq->[1]}++) { # say "target square $sq->[0],$sq->[1]"; @@ -145,7 +145,7 @@ sub move($unit) { @reachable = reading_sort(@reachable); my $target = $reachable[0]; - # say "moving to $target->[0],$target->[1] via $target->[2],$target->[3]"; + say "moving to $target->[0],$target->[1] via $target->[2],$target->[3]"; $map[$unit->[1]][$unit->[0]] = '.'; $map[$unit->[1] = $target->[3]][$unit->[0] = $target->[2]] = $unit->[2]; } @@ -200,9 +200,6 @@ sub battle($elf_hp) { return 1; } -my $elf_hp = 4; +my $elf_hp = 12; $elf_hp++ while !battle($elf_hp); -# There is a bug out there - on the real puzzle input it returned -# remaining hp lower by three, which means there had to be one less Goblin -# attack somewhere. -- 2.43.0