Solve 2024 day 1
This commit is contained in:
21
2024/d1.py
Normal file
21
2024/d1.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from lib import get_data
|
||||||
|
from lib import ints
|
||||||
|
|
||||||
|
data = get_data(__file__)
|
||||||
|
|
||||||
|
s = 0
|
||||||
|
ass, bss = [], []
|
||||||
|
s2 = 0
|
||||||
|
|
||||||
|
# I had an intuition for this and then went for loops...
|
||||||
|
xs, ys = list(zip(*[ints(line) for line in data.splitlines()]))
|
||||||
|
|
||||||
|
xs = sorted(xs)
|
||||||
|
ys = sorted(ys)
|
||||||
|
|
||||||
|
for a, b in zip(xs, ys):
|
||||||
|
s += max(a, b) - min(a, b)
|
||||||
|
s2 += ys.count(a) * a
|
||||||
|
|
||||||
|
print(s)
|
||||||
|
print(s2)
|
||||||
1
2024/lib.py
Symbolic link
1
2024/lib.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../lib.py
|
||||||
@@ -288,3 +288,8 @@ and focus. Of course, learning more algorithms and techniques helps.
|
|||||||
nodes. I should probably try to write an algorith that does that, but meh.
|
nodes. I should probably try to write an algorith that does that, but meh.
|
||||||
Manually plotting requires matplotlib and networkx packages.
|
Manually plotting requires matplotlib and networkx packages.
|
||||||
|
|
||||||
|
|
||||||
|
## AoC 2024
|
||||||
|
|
||||||
|
- Day 1: 1:30/2:49 (124th/141th)
|
||||||
|
- Day 2:
|
||||||
|
|||||||
Reference in New Issue
Block a user