diff --git a/challenges/2023/25-snowverload/README.md b/challenges/2023/25-snowverload/README.md new file mode 100644 index 0000000..7e440a8 --- /dev/null +++ b/challenges/2023/25-snowverload/README.md @@ -0,0 +1 @@ +# [Day 25: Snowverload](https://adventofcode.com/2023/day/25) diff --git a/challenges/2023/25-snowverload/main.py b/challenges/2023/25-snowverload/main.py new file mode 100644 index 0000000..d977877 --- /dev/null +++ b/challenges/2023/25-snowverload/main.py @@ -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)) \ No newline at end of file diff --git a/challenges/2023/25-snowverload/tests.json b/challenges/2023/25-snowverload/tests.json new file mode 100644 index 0000000..b90f46a --- /dev/null +++ b/challenges/2023/25-snowverload/tests.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/challenges/2023/README.md b/challenges/2023/README.md index 0145080..4257efa 100644 --- a/challenges/2023/README.md +++ b/challenges/2023/README.md @@ -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 :( | \ No newline at end of file +| 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. | \ No newline at end of file diff --git a/challenges/2023/benchmark-graph.png b/challenges/2023/benchmark-graph.png index 7c75567..e334f20 100644 Binary files a/challenges/2023/benchmark-graph.png and b/challenges/2023/benchmark-graph.png differ diff --git a/challenges/2023/benchmarks.jsonl b/challenges/2023/benchmarks.jsonl index dc5427f..8786015 100644 --- a/challenges/2023/benchmarks.jsonl +++ b/challenges/2023/benchmarks.jsonl @@ -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}