2023.25
This commit is contained in:
parent
10b2966a85
commit
4dc70015fb
6 changed files with 66 additions and 1 deletions
1
challenges/2023/25-snowverload/README.md
Normal file
1
challenges/2023/25-snowverload/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# [Day 25: Snowverload](https://adventofcode.com/2023/day/25)
|
54
challenges/2023/25-snowverload/main.py
Normal file
54
challenges/2023/25-snowverload/main.py
Normal 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))
|
8
challenges/2023/25-snowverload/tests.json
Normal file
8
challenges/2023/25-snowverload/tests.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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 |
|
@ -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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue