From 267650c4ee958c37705cb144bf1663466874b3be Mon Sep 17 00:00:00 2001 From: Brian Chu Date: Sun, 9 Jan 2022 14:29:44 -0800 Subject: solution for day 22 --- day22.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 day22.py diff --git a/day22.py b/day22.py new file mode 100644 index 0000000..a3f2bbf --- /dev/null +++ b/day22.py @@ -0,0 +1,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) \ No newline at end of file -- cgit 1.4.1-2-gfad0