27 lines
453 B
Python
27 lines
453 B
Python
|
with open('data02.txt') as f:
|
||
|
rows = f.readlines()
|
||
|
|
||
|
|
||
|
'''
|
||
|
# part 1
|
||
|
diffs = []
|
||
|
for r in rows:
|
||
|
cells = [int(c) for c in r.split()]
|
||
|
diffs.append(max(cells) - min(cells))
|
||
|
|
||
|
print(sum(diffs))
|
||
|
'''
|
||
|
|
||
|
# part 2
|
||
|
from itertools import combinations
|
||
|
|
||
|
rows = [[int(x) for x in r.split()] for r in rows]
|
||
|
divs = []
|
||
|
for row in rows:
|
||
|
for pair in combinations(row, 2):
|
||
|
hi, lo = max(pair), min(pair)
|
||
|
if hi % lo == 0:
|
||
|
divs.append(hi // lo)
|
||
|
break
|
||
|
|
||
|
print(sum(divs))
|