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:
14
14
return data
15
15
16
16
17
- # MAIN FUNCTIONS
18
-
17
+ # MAIN
19
18
def part1 (data : List [str ]) -> int :
19
+ """
20
+ find distance between 2 sorted lists
21
+ """
20
22
return sum (abs (a - b )
21
23
for a , b in zip ( # zip 2 lists into a list of tuples and find distance between each item in 2 lists
22
24
* map (sorted , zip (* ( # unzip a list of tuples into 2 lists and sort them
@@ -25,14 +27,16 @@ def part1(data: List[str]) -> int:
25
27
26
28
27
29
def 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
+ """
28
33
loc1 , loc2 = zip (* (tuple (map (int , item .split ())) for item in data ))
29
34
counter = Counter (loc2 )
30
35
return sum (i * counter .get (i , 0 ) for i in loc1 )
31
36
32
37
33
38
# TEST
34
39
def test ():
35
- # GIVEN
36
40
given = parser ("""
37
41
3 4
38
42
4 3
@@ -54,7 +58,7 @@ def test():
54
58
part_1 = part1 (lines )
55
59
print (part_1 )
56
60
assert part_1 == 3_508_942
57
- # # TWO #2
61
+ # TWO #2
58
62
part_2 = part2 (lines )
59
63
print (part_2 )
60
64
assert part_2 == 26_593_248
You can’t perform that action at this time.
0 commit comments