import pandas as pd
import numpy as np
# Ez mode:
test = pd.read_csv("H:/python_jiggering/logs/aoc_2017/d2_input.txt", header = None, sep = '\t')
test.head()
We wanna figure out how to compute the difference between min and max
def check(x):
return(np.max(x) - np.min(x))
Apply across rows:
ranges = test.apply(func = check, axis = 1)
checksum = sum(ranges)
checksum
Okay for the second part we have to find which pair of numbers even divides the other. I think my style is again to just write to do it once and see if we can get the indices. Probably two for loops will do this simply enough...
def check2(x):
for i in range(len(x)):
for j in range(i+1, len(x)):
if x[i] % x[j] == 0:
return(x[i] / x[j])
if x[j] % x[i] == 0:
return(x[j] / x[i])
quotients = test.apply(func = check2, axis = 1)
checksum2 = sum(quotients)
checksum2