File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ def parse (data ):
5
+ data = data .replace (' ' , '\n ' ).split ('\n ' )
6
+ list1 = data [::2 ]
7
+ list2 = data [1 ::2 ]
8
+
9
+ return list1 , list2
10
+
11
+ split_data = parse
12
+ completed = True
13
+ raw_data = None # Not To be touched
14
+
15
+ def part1 (data ):
16
+ list1 , list2 = data
17
+ cum = 0
18
+ for l1 , l2 in zip (sorted (list1 ), sorted (list2 )):
19
+ cum += abs (int (l1 ) - int (l2 ))
20
+
21
+ return cum
22
+
23
+
24
+ def part2 (data ):
25
+ list1 , list2 = data
26
+
27
+ hashmap = {} # Quick hashmap to store the frequency for later use
28
+ for elem in list2 :
29
+ hashmap [elem ] = hashmap .get (elem , 0 ) + 1
30
+
31
+ simScore = 0
32
+ for elem in list1 :
33
+ simScore += int (elem ) * hashmap .get (elem , 0 )
34
+
35
+ return simScore
You can’t perform that action at this time.
0 commit comments