|
|
@ -13,11 +13,8 @@ import numpy as np |
|
|
|
|
|
|
|
|
|
|
|
class Bingo: |
|
|
|
boards: List = [] |
|
|
|
draws: List = [] |
|
|
|
game = None |
|
|
|
winning_board = None |
|
|
|
winning_score = 0 |
|
|
|
boards = None |
|
|
|
draws = None |
|
|
|
|
|
|
|
def __init__(self, inputs: str) -> None: |
|
|
|
inputs = inputs.split("\n\n") |
|
|
@ -32,25 +29,35 @@ class Bingo: |
|
|
|
dtype=object, |
|
|
|
) |
|
|
|
|
|
|
|
def solve(self) -> int: |
|
|
|
self.game = self.boards.copy() |
|
|
|
def solve(self, squid_rules: bool = False) -> int: |
|
|
|
game = self.boards.copy() |
|
|
|
winning_scores = [] |
|
|
|
for draw in self._draw(): |
|
|
|
self.game[self.game == draw] = np.nan |
|
|
|
game[game == draw] = np.nan |
|
|
|
|
|
|
|
for index, board in enumerate(self.game): |
|
|
|
for index, board in enumerate(game): |
|
|
|
if self._is_solved(board): |
|
|
|
self.winning_board = self.boards[index] |
|
|
|
self.winning_score = self.calculate_score(board, draw) |
|
|
|
return self.winning_score |
|
|
|
winning_scores.append(self._calculate_score(board, draw)) |
|
|
|
|
|
|
|
return self.winning_score |
|
|
|
try: |
|
|
|
game = np.delete(game, index, axis=0) |
|
|
|
except IndexError: # I don't understand why this is needed |
|
|
|
# Need to rework the whole class |
|
|
|
# Wrong way to go about this |
|
|
|
pass |
|
|
|
|
|
|
|
if len(winning_scores) == np.size(self.boards, axis=0): |
|
|
|
break |
|
|
|
|
|
|
|
index = -1 if squid_rules else 0 |
|
|
|
return winning_scores[index] |
|
|
|
|
|
|
|
def _draw(self) -> int: |
|
|
|
for draw in self.draws: |
|
|
|
yield draw |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def calculate_score(solved_board, last_draw: int) -> int: |
|
|
|
def _calculate_score(solved_board, last_draw: int) -> int: |
|
|
|
board_score = np.nansum(solved_board) |
|
|
|
return board_score * last_draw |
|
|
|
|
|
|
@ -69,7 +76,7 @@ def part1(inputs: str) -> int: |
|
|
|
|
|
|
|
def part2(inputs: str) -> int: |
|
|
|
game = Bingo(inputs) |
|
|
|
return False |
|
|
|
return game.solve(squid_rules=True) |
|
|
|
|
|
|
|
|
|
|
|
def solve(path: str) -> Tuple[int, int]: |
|
|
|