From: Jan "Yenya" Kasprzak Date: Mon, 19 Dec 2022 14:27:36 +0000 (+0100) Subject: Day 19: pruning by remaining time (credits: Honza Obdrzalek) X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=5d0046af83214098fcb93ae28a1a40557a6f1844;p=aoc.git Day 19: pruning by remaining time (credits: Honza Obdrzalek) --- diff --git a/2022/38.pl b/2022/38.pl index f72f5c4..91bc477 100755 --- a/2022/38.pl +++ b/2022/38.pl @@ -25,7 +25,7 @@ while (<>) { say $prod; sub dfs($g) { - my @q = ([ 0, [ 1, 0, 0, 0 ], [ 0, 0, 0, 0 ], 0, 0 ]); + my @q = ([ 32, [ 1, 0, 0, 0 ], [ 0, 0, 0, 0 ], 0, 0 ]); my @needed; for my $rob (0 .. 3) { for my $comp (0 .. 2) { @@ -39,13 +39,15 @@ sub dfs($g) { while (@q) { my ($t, $robs, $inv, $cantbuy, $didntbuy) = @{ shift @q }; - if ($t++ == 32) { + if (!$t) { if ($inv->[3] > $mx) { $mx = $inv->[3]; say " $mx"; } next; } + next if $t*$robs->[3] + $inv->[3] + ($t*($t-1)/2) <= $mx; + $t--; my @ni = @$inv; for (0 .. 3) { @@ -57,12 +59,11 @@ sub dfs($g) { my $bp = $g->[$bpn]; my $mask = 1 << $bpn; next if $cantbuy & $mask; + next if $didntbuy & $mask; if ($bpn < 3 && $robs->[$bpn] >= $needed[$bpn]) { $cantbuy |= $mask; next; } - - next if $didntbuy & $mask; for (0 .. 2) { next ROBOT if $bp->[$_] > $inv->[$_]; }