From 89bbf2ee9043463db03b5e7ea6675c42c29a0284 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sun, 18 Dec 2022 13:15:08 +0000 Subject: 16 p2 attempt --- 16.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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]) -- cgit v1.2.3-54-g00ecf