X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=2018%2F30.pl;h=663fa08fa4bec95dc09ccc11aeb95ac8a4c50a32;hb=8c035a6f79767d1e9f2f2290bbf27de2e1485793;hp=61e60e5451fcdf255ba494d900aa5980076d0a1a;hpb=4fc399ecb8a8626d476087a9ec1809e260a8268c;p=aoc.git 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.