-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.py
37 lines (27 loc) · 826 Bytes
/
day2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from itertools import permutations
def checksum(matrix):
total = 0
for row in matrix:
total += (max(row) - min(row))
return total
def checksum2(matrix):
total = 0
for row in matrix:
pairs = permutations(row, 2)
for pair in pairs:
if not pair[0] == pair[1]:
if pair[0] % pair[1] == 0:
total += (pair[0] / pair[1])
return total
def create_matrix(lines): # pragma: no cover
matrix = []
for row in lines:
matrix.append([int(i) for i in row.split()])
return matrix
def main(): # pragma: no cover
with open('day2_input.txt') as f:
matrix = create_matrix(f.readlines())
print(checksum(matrix))
print(checksum2(matrix))
if __name__ == '__main__': # pragma: no cover
main()