Compare commits
No commits in common. "909b0d3b40a3e49bacb82fc70c7917a2b5fb0a41" and "15b4f24087b9d96e8aed984e690dab63c54284b3" have entirely different histories.
909b0d3b40
...
15b4f24087
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
*/inputs
|
||||
**/__pycache__
|
||||
.venv
|
@ -5,8 +5,6 @@ Jour 24 du défi Advent Of Code pour l'année 2023
|
||||
import os
|
||||
import z3
|
||||
|
||||
from aoc_utils import decorators
|
||||
|
||||
def read_sample():
|
||||
"""récupère les entrées depuis le fichier texte correspondant"""
|
||||
filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day24.txt")
|
||||
@ -49,7 +47,7 @@ def intersection(h1, h2):
|
||||
return x, y
|
||||
|
||||
|
||||
@decorators.timeit
|
||||
|
||||
def part1(sample, left=200000000000000, right=400000000000000):
|
||||
"""Partie 1 du défi"""
|
||||
hailstones = [Hailstone(i) for i in sample]
|
||||
@ -65,13 +63,12 @@ def part1(sample, left=200000000000000, right=400000000000000):
|
||||
|
||||
return count
|
||||
|
||||
@decorators.timeit
|
||||
def part2(sample):
|
||||
"""Partie 2 du défi"""
|
||||
hailstones = [Hailstone(i) for i in sample]
|
||||
|
||||
px, py, pz, dx, dy, dz = z3.Reals("px py pz dx dy dz")
|
||||
collision = [z3.Real("t"+str(i)) for i in range(len(hailstones))]
|
||||
px, py, pz, dx, dy, dz = z3.Ints("px py pz dx dy dz")
|
||||
collision = [z3.Int("t"+str(i)) for i in range(len(hailstones))]
|
||||
solver = z3.Solver()
|
||||
for i in range(len(hailstones)):
|
||||
h = hailstones[i]
|
||||
|
@ -1,77 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
"""
|
||||
Jour 25 du défi Advent Of Code pour l'année 2023
|
||||
"""
|
||||
import os
|
||||
|
||||
import networkx as nx
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from aoc_utils import graph
|
||||
|
||||
def read_sample():
|
||||
"""récupère les entrées depuis le fichier texte correspondant"""
|
||||
filename = os.path.join(os.path.dirname(__file__ ), "inputs", "day25.txt")
|
||||
with open(filename, 'r') as f:
|
||||
sample = f.read().split('\n')
|
||||
sample = [ i for i in sample if i != '' ]
|
||||
return sample
|
||||
|
||||
def create_graph(sample):
|
||||
g = graph.Graph()
|
||||
for line in sample:
|
||||
node = line.split(": ")[0]
|
||||
dests = line.split(": ")[1].split()
|
||||
if node not in g:
|
||||
g.add_node(node)
|
||||
|
||||
for dest in dests:
|
||||
if dest not in [i[0] for i in g[node]]:
|
||||
g.add_edge(node, dest)
|
||||
|
||||
return g
|
||||
|
||||
|
||||
|
||||
def part1(sample):
|
||||
"""Partie 1 du défi"""
|
||||
g = create_graph(sample)
|
||||
|
||||
ng = g.networkx()
|
||||
cut, parts = nx.stoer_wagner(ng)
|
||||
|
||||
assert cut == 3
|
||||
assert len(parts) == 2
|
||||
|
||||
return len(parts[0])*len(parts[1])
|
||||
|
||||
#* Initial code:
|
||||
"""
|
||||
ng = g.networkx()
|
||||
nx.draw(ng, with_labels=True)
|
||||
plt.savefig("path.png")
|
||||
|
||||
to_delete = [("vqj", "szh"), ("jbx", "sml"), ("zhb", "vxr")]
|
||||
#to_delete = [("hfx", "pzl"), ("bvb", "cmg"), ("nvd", "jqt")]
|
||||
for edge in to_delete:
|
||||
g.remove_edges(*edge)
|
||||
|
||||
|
||||
ccs = g.connexes()
|
||||
print([len(i) for i in ccs])
|
||||
return len(ccs[0])*len(ccs[1])
|
||||
"""
|
||||
|
||||
def part2(sample):
|
||||
"""Partie 2 du défi"""
|
||||
return "Go push the big red button"
|
||||
|
||||
|
||||
def main():
|
||||
"""Fonction principale"""
|
||||
sample = read_sample()
|
||||
print(f"part1: {part1(sample)}")
|
||||
print(f"part2: {part2(sample)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,8 +1,5 @@
|
||||
from collections.abc import Mapping
|
||||
from typing import TypeVar, Optional, Iterator, Generic
|
||||
import networkx as nx
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
@ -107,35 +104,3 @@ class Graph(Mapping, Generic[T]):
|
||||
raise ValueError("Graph contains a negative cycle")
|
||||
|
||||
return distances, predecessors
|
||||
|
||||
def networkx(self):
|
||||
g = nx.Graph()
|
||||
g.add_nodes_from(self)
|
||||
for node in self:
|
||||
for dest, _ in self[node]:
|
||||
g.add_edge(node, dest)
|
||||
|
||||
return g
|
||||
|
||||
def dfs(self, node, views=None):
|
||||
if views is None:
|
||||
views = set()
|
||||
|
||||
views.add(node)
|
||||
if node in self:
|
||||
for v, _ in self[node]:
|
||||
if v not in views:
|
||||
views = views | self.dfs(v, views=views)
|
||||
return views
|
||||
|
||||
def connexes(self):
|
||||
views = set()
|
||||
|
||||
ccs = []
|
||||
for node in self:
|
||||
if node not in views:
|
||||
cur_views = self.dfs(node)
|
||||
ccs.append(cur_views)
|
||||
views = views | cur_views
|
||||
|
||||
return ccs
|
@ -1,6 +0,0 @@
|
||||
tqdm
|
||||
z3-solver
|
||||
matplotlib
|
||||
networkx
|
||||
requests
|
||||
beautifulsoup
|
Loading…
x
Reference in New Issue
Block a user