From d02f63a4ef8f5e10477d0c73384dcbe16cfc2b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Thu, 12 Dec 2024 13:16:31 +0100 Subject: [PATCH] Solve 2016:22 p2 "Grid Computing" Solved by hand by visualizing the filesystem as a grid, and put into a simple formula. In Sweden, this is called a "Femtonspel". https://sv.wikipedia.org/wiki/Femtonspel --- 2016-python2/output/day_22.py | 40 +++++++---------------------------- 2016-python2/output/day_24.py | 19 ----------------- 2 files changed, 8 insertions(+), 51 deletions(-) diff --git a/2016-python2/output/day_22.py b/2016-python2/output/day_22.py index 8a35faf..1b885d1 100644 --- a/2016-python2/output/day_22.py +++ b/2016-python2/output/day_22.py @@ -1,9 +1,6 @@ -import re -from collections import Counter, defaultdict, deque -from heapq import heappop, heappush -from itertools import chain, combinations, compress, permutations +from itertools import permutations -from output import ADJ, DD, D, ints, matrix, mdbg, mhd, vdbg +from output import ints def solve(data): @@ -19,14 +16,18 @@ def solve(data): grid[(y1, x1)] = (used, size) if 0 < used <= avail: viable.add(((y1, x1), (y2, x2))) + if used == 0: + empty = (y1, x1) p1 = len(viable) S, E = (0, W), (0, 0) - H, W = H + 1, W + 1 - dagrid(grid, H, W) + # dagrid(grid, H + 1, W + 1) + y, x = empty + p2 = x + y + W + (W - 1) * 5 return p1, p2 def dagrid(grid, H, W): + """Used to print the grid to be solved by hand.""" for r in range(H): for c in range(W): u, a = grid[(r, c)] @@ -35,35 +36,10 @@ def dagrid(grid, H, W): if __name__ == "__main__": - # use dummy data - inp = """ - sdsdsd - Filesystem Size Used Avail Use% - /dev/grid/node-x0-y0 10T 8T 2T 80% - /dev/grid/node-x0-y1 11T 6T 5T 54% - /dev/grid/node-x0-y2 32T 28T 4T 87% - /dev/grid/node-x1-y0 9T 7T 2T 77% - /dev/grid/node-x1-y1 8T 0T 8T 0% - /dev/grid/node-x1-y2 11T 7T 4T 63% - /dev/grid/node-x2-y0 10T 6T 4T 60% - /dev/grid/node-x2-y1 9T 8T 1T 88% - /dev/grid/node-x2-y2 9T 6T 3T 66% - """.strip() - - # uncomment to instead use stdin - # import sys; inp = sys.stdin.read().strip() - - # uncomment to use AoC provided puzzle input with open("./input/22.txt", "r") as f: inp = f.read().strip() - # uncomment to do initial data processing shared by part 1-2 p1, p2 = solve(inp) print(p1) print(p2) - - # uncomment and replace 0 with actual output to refactor code - # and ensure nonbreaking changes - # assert p1 == 0 - # assert p2 == 0 diff --git a/2016-python2/output/day_24.py b/2016-python2/output/day_24.py index d2c7645..43ec8ad 100644 --- a/2016-python2/output/day_24.py +++ b/2016-python2/output/day_24.py @@ -49,29 +49,10 @@ def travel(dests, grid, H, W, S0, goback=False): if __name__ == "__main__": - # use dummy data - inp = """ - ########### - #0.1.....2# - #.#######.# - #4.......3# - ########### - """.strip() - - # uncomment to instead use stdin - # import sys; inp = sys.stdin.read().strip() - - # uncomment to use AoC provided puzzle input with open("./input/24.txt", "r") as f: inp = f.read().strip() - # uncomment to do initial data processing shared by part 1-2 p1, p2 = solve(inp) print(p1) print(p2) - - # uncomment and replace 0 with actual output to refactor code - # and ensure nonbreaking changes - # assert p1 == 0 - # assert p2 == 0