]> www.fi.muni.cz Git - aoc.git/commitdiff
Fixup for 2018 day 15/2
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 25 Nov 2022 08:08:47 +0000 (09:08 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 25 Nov 2022 08:08:47 +0000 (09:08 +0100)
2018/30.pl

index 61e60e5451fcdf255ba494d900aa5980076d0a1a..663fa08fa4bec95dc09ccc11aeb95ac8a4c50a32 100755 (executable)
@@ -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.