generated from public/aoc_template
Compare commits
2 Commits
5765f27501
...
b053e244e4
| Author | SHA1 | Date | |
|---|---|---|---|
| b053e244e4 | |||
| 67a278ce0c |
14
day22.py
14
day22.py
@ -59,11 +59,21 @@ class Day(AOCDay):
|
||||
|
||||
def part1(self) -> Any:
|
||||
dropped_bricks, _ = drop(self.parse_input())
|
||||
return sum(c[1] == 0 for c in (drop(dropped_bricks - {x}) for x in dropped_bricks))
|
||||
count = 0
|
||||
for brick in dropped_bricks:
|
||||
_, c = drop(dropped_bricks - {brick})
|
||||
count += c == 0
|
||||
self.progress(len(dropped_bricks))
|
||||
return count
|
||||
|
||||
def part2(self) -> Any:
|
||||
dropped_bricks, _ = drop(self.parse_input())
|
||||
return sum(c[1] for c in (drop(dropped_bricks - {x}) for x in dropped_bricks))
|
||||
count = 0
|
||||
for brick in dropped_bricks:
|
||||
_, c = drop(dropped_bricks - {brick})
|
||||
count += c
|
||||
self.progress(len(dropped_bricks))
|
||||
return count
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
2
day24.py
2
day24.py
@ -57,6 +57,8 @@ class Day(AOCDay):
|
||||
|
||||
def part2(self) -> Any:
|
||||
# moving to position 24, 13, 10 and throwing the rock at velocity -3, 1, 2.
|
||||
|
||||
# Maybe we can find some parallel running hailstones and go from there somehow?
|
||||
hailstones = self.parse_input(True)
|
||||
return ""
|
||||
|
||||
|
||||
119
day25.py
Normal file
119
day25.py
Normal file
@ -0,0 +1,119 @@
|
||||
from __future__ import annotations
|
||||
from collections import deque
|
||||
from tools.aoc import AOCDay
|
||||
from tools.itertools import len_permutations
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Component:
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
self.connections = set()
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.name)
|
||||
|
||||
|
||||
def separate(component1: Component, component2: Component) -> (int, int, int):
|
||||
""" returns len(group1), len(group2), len(wires_to_disconnect)"""
|
||||
group1, group2, wires_to_disconnect = set(), set(), set()
|
||||
q1, q2 = deque([component1]), deque([component2])
|
||||
while q1 or q2:
|
||||
if q1 and len(q1) != 3:
|
||||
c1 = q1.popleft()
|
||||
if c1 in group1 or c1 in group2:
|
||||
continue
|
||||
group1.add(c1)
|
||||
for c in c1.connections:
|
||||
if c in group2:
|
||||
wires_to_disconnect.add((c1, c) if c1.name < c.name else (c, c1))
|
||||
else:
|
||||
q1.append(c)
|
||||
|
||||
if q2 and len(q2) != 3:
|
||||
c2 = q2.popleft()
|
||||
if c2 in group1 or c2 in group2:
|
||||
continue
|
||||
group2.add(c2)
|
||||
for c in c2.connections:
|
||||
if c in group1:
|
||||
wires_to_disconnect.add(((c2, c) if c2.name < c.name else (c, c2)))
|
||||
else:
|
||||
q2.append(c)
|
||||
|
||||
if len(q1) == 3 and len(q2) == 3:
|
||||
return len(group1), len(group2), len(wires_to_disconnect)
|
||||
|
||||
return len(group1), len(group2), len(wires_to_disconnect)
|
||||
|
||||
|
||||
class Wiring:
|
||||
def __init__(self):
|
||||
self.components = {}
|
||||
|
||||
def get_component(self, name: str):
|
||||
if name not in self.components:
|
||||
self.components[name] = Component(name)
|
||||
|
||||
return self.components[name]
|
||||
|
||||
def get_connections(self) -> set:
|
||||
connections = set()
|
||||
for component in self.components.values():
|
||||
for connection in component.connections:
|
||||
connections.add((component.name, connection.name) if component.name < connection.name else (connection.name, component.name))
|
||||
|
||||
return connections
|
||||
|
||||
@classmethod
|
||||
def from_input(cls, data: list[str]) -> Wiring:
|
||||
wiring = cls()
|
||||
for line in data:
|
||||
left, rights = line.split(": ")
|
||||
rights = rights.split()
|
||||
|
||||
left = wiring.get_component(left)
|
||||
for r in rights:
|
||||
right = wiring.get_component(r)
|
||||
left.connections.add(right)
|
||||
right.connections.add(left)
|
||||
|
||||
return wiring
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
#(54, "input25_test"), # Test breaks sometimes. Live always works?!
|
||||
(544523, "input25"),
|
||||
],
|
||||
[
|
||||
(None, "input25"),
|
||||
]
|
||||
]
|
||||
|
||||
def part1(self) -> Any:
|
||||
wiring = Wiring.from_input(self.getInput())
|
||||
the_first = wiring.get_component(next(iter(wiring.components)))
|
||||
for component in wiring.components.values():
|
||||
if component == the_first:
|
||||
continue
|
||||
|
||||
g1, g2, c = separate(the_first, component)
|
||||
if c == 3:
|
||||
return g1 * g2
|
||||
|
||||
g1, g2, c = separate(component, the_first)
|
||||
if c == 3:
|
||||
return g1 * g2
|
||||
|
||||
print("Missed, try again.")
|
||||
return ""
|
||||
|
||||
def part2(self) -> Any:
|
||||
return ""
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
day = Day(2023, 25)
|
||||
day.run(verbose=True)
|
||||
1196
inputs/input25
Normal file
1196
inputs/input25
Normal file
File diff suppressed because it is too large
Load Diff
13
inputs/input25_test
Normal file
13
inputs/input25_test
Normal file
@ -0,0 +1,13 @@
|
||||
jqt: rhn xhk nvd
|
||||
rsh: frs pzl lsr
|
||||
xhk: hfx
|
||||
cmg: qnr nvd lhk bvb
|
||||
rhn: xhk bvb hfx
|
||||
bvb: xhk hfx
|
||||
pzl: lsr hfx nvd
|
||||
qnr: nvd
|
||||
ntq: jqt hfx bvb xhk
|
||||
nvd: lhk
|
||||
lsr: lhk
|
||||
rzs: qnr cmg lsr rsh
|
||||
frs: qnr lhk lsr
|
||||
Loading…
Reference in New Issue
Block a user