In [19]:
myinput = '/home/fmuinos/projects/adventofcode/2016/ferran/inputs/input22.txt'
In [41]:
import pandas as pd
import re
def read_table(myinput):
df = pd.DataFrame.from_csv(myinput, sep='\s+', header=0)
mydict = {}
COORDS = re.compile('/dev/grid/node-x(\d+)-y(\d+)')
LOAD = re.compile('(\d+)T')
for ind, row in df.iterrows():
m = COORDS.match(ind)
x, y = m.groups()
m = LOAD.match(row['Used'])
a = m.groups()
m = LOAD.match(row['Avail'])
b = m.groups()
mydict[(int(x),int(y))] = (int(a[0]), int(b[0]))
return mydict
def viable(A, B):
if A[1][0] > 0:
if A[0] != B[0]:
if A[1][0] < B[1][1]:
return True
return False
In [40]:
cluster_dict = read_table(myinput)
counter = 0
for iti in list(cluster_dict.items()):
for itj in list(cluster_dict.items()):
if viable(iti, itj):
counter += 1
print(counter)
In [ ]: