From cdf7dacff15f62dde0766e4d189e65c4d55659c0 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 4 Dec 2021 23:49:20 +0000 Subject: day 4 numpy: remove reliance on hardcoded BOARD_SIZE --- 4np.py | 6 +++--- 1 file 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) -- cgit v1.2.3-54-g00ecf