This commit is contained in:
akp 2023-12-25 20:21:11 +00:00
parent 10b2966a85
commit 4dc70015fb
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755
6 changed files with 66 additions and 1 deletions

View file

@ -0,0 +1 @@
# [Day 25: Snowverload](https://adventofcode.com/2023/day/25)

View file

@ -0,0 +1,54 @@
import sys
import networkx as nx
import random
from collections import defaultdict
from functools import reduce
def parse(instr: str) -> nx.Graph:
g = nx.Graph()
for line in instr.splitlines():
node, next_nodes = line.split(": ")
next_nodes = next_nodes.split(" ")
for x in zip([node] * len(next_nodes), next_nodes):
g.add_nodes_from(x)
g.add_edge(*x, capacity=1)
return g
def one(instr: str):
g = parse(instr)
nodes = list(g.nodes())
cut = 0
split_nodes = None
while cut != 3:
x = random.choices(nodes, k=2)
if x[0] == x[1]:
continue
cut, nodes = nx.minimum_cut(g, *x, flow_func=nx.algorithms.flow.shortest_augmenting_path)
split_nodes = nodes
assert split_nodes is not None
return reduce(lambda acc, x: acc * len(x), split_nodes, 1)
def two(_: str):
return "Merry Christmas!"
def _debug(*args, **kwargs):
kwargs["file"] = sys.stderr
print(*args, **kwargs)
if __name__ == "__main__":
if len(sys.argv) < 2 or sys.argv[1] not in ["1", "2"]:
print("Missing day argument", file=sys.stderr)
sys.exit(1)
inp = sys.stdin.read().strip()
if sys.argv[1] == "1":
print(one(inp))
else:
print(two(inp))

View file

@ -0,0 +1,8 @@
{
"1": [
{
"is": "54",
"input": "jqt: rhn xhk nvd\nrsh: frs pzl lsr\nxhk: hfx\ncmg: qnr nvd lhk bvb\nrhn: xhk bvb hfx\nbvb: xhk hfx\npzl: lsr hfx nvd\nqnr: nvd\nntq: jqt hfx bvb xhk\nnvd: lhk\nlsr: lhk\nrzs: qnr cmg lsr rsh\nfrs: qnr lhk lsr\n\n"
}
]
}

View file

@ -35,4 +35,5 @@ A day denoted with a star means it has a visualisation.
| 21 - Step Counter | ★ ☆ | Python | ??? |
| 22 - Sand Slabs | ★ ★ | Python | I maintain that OpenSCAD is the best AoC 3D debugging tool |
| 23 - A Long Walk | ★ ★ | Python | Both parts here could theorietcially be done with the same implementation but I couldn't be bothered to rework the part 2 solution to work for part 1 as well. |
| 24 - Never Tell Me The Odds | ★ ★ | Python | Z3 seems like an *incredible* useful tool but also not a satisfying puzzle at all :( |
| 24 - Never Tell Me The Odds | ★ ★ | Python | Z3 seems like an *incredible* useful tool but also not a satisfying puzzle at all :( |
| 25 - Snowverload | ★ ☆ | Python | This... sometimes works? If it fails, re-run it and tadah and then it works. Definitely is user error. |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Before After
Before After

View file

@ -43,3 +43,4 @@
{"day": 23, "part": 2, "runner": "py", "min": 33.72923398017883, "max": 33.72923398017883, "avg": 33.72923398017883, "n": 1}
{"day": 24, "part": 1, "runner": "py", "min": 0.12593984603881836, "max": 0.1335890293121338, "avg": 0.13133821487426758, "n": 5}
{"day": 24, "part": 2, "runner": "py", "min": 4.988582134246826, "max": 6.0756916999816895, "avg": 5.414014768600464, "n": 5}
{"day": 25, "part": 1, "runner": "py", "min": 0.3831920623779297, "max": 0.38574719429016113, "avg": 0.3844696283340454, "n": 2}