summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-04 23:49:20 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-04 23:49:20 +0000
commitcdf7dacff15f62dde0766e4d189e65c4d55659c0 (patch)
treef9534b829ba5ff88d5b31031ccc8783c6da22ccb
parentfc0c4a3195627d0db77bf5701eeebf8706de8b77 (diff)
downloadaoc2021-cdf7dacff15f62dde0766e4d189e65c4d55659c0.tar.gz
aoc2021-cdf7dacff15f62dde0766e4d189e65c4d55659c0.tar.xz
aoc2021-cdf7dacff15f62dde0766e4d189e65c4d55659c0.zip
day 4 numpy: remove reliance on hardcoded BOARD_SIZE
-rw-r--r--4np.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/4np.py b/4np.py
index ad04746..1af238e 100644
--- a/4np.py
+++ b/4np.py
@@ -1,13 +1,13 @@
import numpy as np
from utils import open_day
-BOARD_SIZE = 5
-
nums, boards = open_day(4).read().rstrip().split('\n\n', maxsplit=1)
nums = np.fromstring(nums, sep=',', dtype=int)
numidxs = np.empty(nums.size, dtype=int)
numidxs[nums] = np.arange(nums.size)
-boards = np.fromstring(boards.replace('\n', ' '), sep=' ', dtype=int).reshape(-1, BOARD_SIZE, BOARD_SIZE)
+board, _ = boards.split('\n\n', maxsplit=1)
+board = [list(row.split()) for row in board.split('\n')]
+boards = np.fromstring(boards.replace('\n', ' '), sep=' ', dtype=int).reshape(-1, len(board), len(board[0]))
rboards = numidxs[boards]
colmins = np.amin(np.amax(rboards, axis=1), axis=1)
rowmins = np.amin(np.amax(rboards, axis=2), axis=1)