diff options
-rw-r--r-- | 4np.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -0,0 +1,17 @@ +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) +rboards = numidxs[boards] +colmins = np.amin(np.amax(rboards, axis=1), axis=1) +rowmins = np.amin(np.amax(rboards, axis=2), axis=1) +mins = np.amin(np.stack((colmins, rowmins)), axis=0) +sums = np.sum(boards, axis=(1, 2), where=(rboards > np.expand_dims(mins, (-1, -2)))) * nums[mins] +print(sums[np.argmin(mins)]) +print(sums[np.argmax(mins)]) |