File tree Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 99
1010repos :
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
Original file line number Diff line number Diff line change 99799783201 80983
99899857980 35192
99999958451 71130
1000- 81627 56209
1000+ 81627 56209
Original file line number Diff line number Diff line change 11def 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+
78def 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+
1214def 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
22254 3
23262 5
@@ -32,4 +35,3 @@ def main(part: int = 1) -> int:
3235 assert similarity_score (locations ) == 31
3336
3437 print (main (part = 2 ))
35-
You can’t perform that action at this time.
0 commit comments