-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday22.py
56 lines (40 loc) · 1.15 KB
/
day22.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import get_input
day = int(os.path.basename(__file__).replace('day', '').replace('.py', ''))
data = get_input.get_input(day)
lines = data.split('\n')
# Filesystem Size Used Avail Use%
# /dev/grid/node-x0-y0 88T 67T 21T 76%
nodes = {}
x_max = -1
y_max = -1
for line in lines[2:]:
parts = [x for x in line.split(' ') if x]
subparts = parts[0].split('-')
x = int(subparts[1].replace('x', ''))
y = int(subparts[2].replace('y', ''))
if y > y_max:
y_max = y
if x > x_max:
x_max = x
used = int(parts[2].replace('T', ''))
avail = int(parts[3].replace('T', ''))
nodes[(x,y)] = (used, avail)
viable_pairs = []
for a in nodes.keys():
for b in nodes.keys():
if a == b:
continue
if 0 < nodes[a][0] <= nodes[b][1]:
viable_pairs.append((a, b))
print('Viable pairs: {}'.format(len(viable_pairs)))
for y in range(y_max+1):
for x in range(x_max+1):
if nodes[(x,y)][0] == 0:
print('_', end='')
elif nodes[(x,y)][0] < 100:
print('.', end='')
else:
print('#', end='')
print('')
# 225