diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-18 13:15:08 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-18 13:19:26 +0000 |
commit | 89bbf2ee9043463db03b5e7ea6675c42c29a0284 (patch) | |
tree | dd52a3221d1f247d73965a0e99199142099b5248 | |
parent | 2b6b5944d325846f1490e7f521ead7148639a1a0 (diff) | |
download | aoc2022-89bbf2ee9043463db03b5e7ea6675c42c29a0284.tar.gz aoc2022-89bbf2ee9043463db03b5e7ea6675c42c29a0284.tar.xz aoc2022-89bbf2ee9043463db03b5e7ea6675c42c29a0284.zip |
16 p2 attempt
-rw-r--r-- | 16.py | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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]) |