summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--16.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/16.py b/16.py
index cd27325..8135d87 100644
--- a/16.py
+++ b/16.py
@@ -2,6 +2,7 @@ from utils import open_day
from functools import cache
from dataclasses import dataclass
from itertools import count, chain
+from concurrent import futures
import re
@dataclass
@@ -73,3 +74,26 @@ def solve(nodes, open_valves=1, time_left=30):
v, p = solve(nodes)
print(v, [extern(s) for s in p])
+
+with futures.ProcessPoolExecutor(max_workers=5) as executor:
+ seen = set()
+ perms = 2 ** len(nodes)
+ def solve2(nodes, a, b):
+ return solve(nodes, a, 26), solve(nodes, b, 26)
+ futs = []
+ for i in range(perms):
+ a = i | 1
+ b = (i ^ (perms - 1)) | 1
+ if a in seen or b in seen: continue
+ seen.add(a)
+ seen.add(b)
+ futs.append(executor.submit(solve2, nodes, a, b))
+ best = (0, None, None)
+ for future in futures.as_completed(futs):
+ av, bv = future.result()
+ total = av[0] + bv[0]
+ if total > best[0]:
+ best = total, av[1], bv[1]
+
+v, p1, p2 = best
+print(v, [extern(s) for s in p1], [extern(s) for s in p2])