Skip to content

Commit b0b7366

Browse files
committed
2024: Day 1
1 parent da52dbb commit b0b7366

12 files changed

+1165
-0
lines changed

2024/python/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
venv
2+
session_id.txt

2024/python/.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.4

2024/python/Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
setup:
2+
[ -d venv ] || python -m venv venv
3+
source venv/bin/activate && pip install -r requirements.txt
4+
.PHONY: setup
5+
6+
fetch:
7+
source venv/bin/activate && python -m scripts.fetch_input
8+
.PHONY: fetch
9+
10+
lint:
11+
python -m isort .
12+
python -m black .
13+
.PHONY: lint
14+
15+
mypy:
16+
python -m mypy .
17+
.PHONY: lint

2024/python/day1/__init__.py

Whitespace-only changes.

2024/python/day1/__main__.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from collections import Counter
2+
3+
from utils.file import read_input
4+
5+
6+
def main() -> None:
7+
lines = read_input(__package__)
8+
l1 = sorted(int(line[:5]) for line in lines)
9+
l2 = sorted(int(line[8:14]) for line in lines)
10+
11+
distance = sum(abs(a - b) for a, b in zip(l1, l2))
12+
print("Part 1:", distance)
13+
14+
c = Counter(l2)
15+
similarity = sum(n * c[n] for n in set(l1))
16+
print("Part 2:", similarity)
17+
18+
19+
if __name__ == "__main__":
20+
main()

0 commit comments

Comments
 (0)