summary refs log tree commit diff stats
path: root/day22.py
blob: a3f2bbf81ac473e5006f8362d938696826f7c966 (plain) (blame)
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
import re
import numpy as np

with open('day22.txt', 'r') as infile:
    lines = infile.read().split('\n')

avail = []
used = []
grid = [['.' for _ in range(34)] for _ in range(30)]

for line in lines[2:]:
    sizes = re.search(r'x(\d+)-y(\d+).+T\s+(\d+)T\s+(\d+)T\s+\d+%', line)
    if line == '': continue
    x = int(sizes.group(1))
    y = int(sizes.group(2))
    usd = int(sizes.group(3))
    avl = int(sizes.group(4))
    used.append(usd)
    avail.append(avl)
    if usd > 100:
        grid[y][x] = '#'
    elif usd == 0:
        grid[y][x] = '_'

grid[0][-1] = 'G'
grid[0][0] = 'F'

uss = np.array(used)
print(sum((uss <= 94) & (uss > 0)))

for line in grid:
    print(''.join(line))

start = (6, grid[6].index('_'))
wall = (5, grid[5].index('#')-1)
goal = (0, len(grid[0])-1)
finish = (0, 0)

def get_manhattan(a, b):
    x1, y1 = a
    x2, y2 = b
    return abs(x2 - x1) + abs(y2 - y1)

steps = get_manhattan(start, wall)
steps += get_manhattan(wall, goal)
steps += 5 * (goal[1] - 1)
print(steps)