summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2022-01-09 14:29:44 -0800
committerBrian Chu <brianmchu42@gmail.com>2022-01-09 14:29:44 -0800
commit267650c4ee958c37705cb144bf1663466874b3be (patch)
tree59356a8f8c3161bea59c9d9a78a763101df92a5e
parent5f10a7c655aacbbc7f4f67607d758c65f196f436 (diff)
downloadAdventOfCode2016-267650c4ee958c37705cb144bf1663466874b3be.tar.gz
solution for day 22
-rw-r--r--day22.py47
1 files changed, 47 insertions, 0 deletions
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