Skip to content

Commit bddd670

Browse files
committed
Lint 2024 day 1
1 parent 573f5ad commit bddd670

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
repos:
1111
- repo: https://github.com/pre-commit/pre-commit-hooks
12-
rev: v4.4.0
12+
rev: v5.0.0
1313
hooks:
1414
- id: check-yaml
1515
- id: check-toml

2024/data/day01.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,4 +997,4 @@
997997
83201 80983
998998
57980 35192
999999
58451 71130
1000-
81627 56209
1000+
81627 56209

2024/day01.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
def total_distance(locations):
22
rows = (map(int, loc.split()) for loc in locations.splitlines())
33
columns = map(sorted, zip(*rows))
4-
diffs = (abs(a-b) for (a, b) in zip(*columns))
4+
diffs = (abs(a - b) for (a, b) in zip(*columns))
55
return sum(diffs)
66

7+
78
def similarity_score(locations):
89
rows = (map(int, loc.split()) for loc in locations.splitlines())
910
left_column, right_column = zip(*rows)
1011
return sum(number * right_column.count(number) for number in left_column)
11-
12+
13+
1214
def main(part: int = 1) -> int:
1315
with open("2024/data/day01.txt") as f:
1416
locations = f.read()
15-
if part ==1:
17+
if part == 1:
1618
return total_distance(locations)
1719
else:
1820
return similarity_score(locations)
19-
20-
if __name__ == '__main__':
21+
22+
23+
if __name__ == "__main__":
2124
locations = """3 4
2225
4 3
2326
2 5
@@ -32,4 +35,3 @@ def main(part: int = 1) -> int:
3235
assert similarity_score(locations) == 31
3336

3437
print(main(part=2))
35-

0 commit comments

Comments
 (0)