File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,11 @@ def read_input() -> str:
1414 return data
1515
1616
17- # MAIN FUNCTIONS
18-
17+ # MAIN
1918def part1 (data : List [str ]) -> int :
19+ """
20+ find distance between 2 sorted lists
21+ """
2022 return sum (abs (a - b )
2123 for a , b in zip ( # zip 2 lists into a list of tuples and find distance between each item in 2 lists
2224 * map (sorted , zip (* ( # unzip a list of tuples into 2 lists and sort them
@@ -25,14 +27,16 @@ def part1(data: List[str]) -> int:
2527
2628
2729def part2 (data : List [str ]) -> int :
30+ """
31+ find similarity score based on how many times an item from left list appears in the right one
32+ """
2833 loc1 , loc2 = zip (* (tuple (map (int , item .split ())) for item in data ))
2934 counter = Counter (loc2 )
3035 return sum (i * counter .get (i , 0 ) for i in loc1 )
3136
3237
3338# TEST
3439def test ():
35- # GIVEN
3640 given = parser ("""
37413 4
38424 3
@@ -54,7 +58,7 @@ def test():
5458 part_1 = part1 (lines )
5559 print (part_1 )
5660 assert part_1 == 3_508_942
57- # # TWO #2
61+ # TWO #2
5862 part_2 = part2 (lines )
5963 print (part_2 )
6064 assert part_2 == 26_593_248
You can’t perform that action at this time.
0 commit comments