Browse Source

Reworking for part 2

pull/4/head
Ryan Reed 3 years ago
parent
commit
f02760c5e1
2 changed files with 24 additions and 19 deletions
  1. +22
    -15
      puzzles/day04.py
  2. +2
    -4
      puzzles/test_day04.py

+ 22
- 15
puzzles/day04.py View File

@ -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]:


+ 2
- 4
puzzles/test_day04.py View File

@ -20,15 +20,13 @@ def test_example1(example_data):
assert aoc.part1(example_data) == 4512
@pytest.mark.skip(reason="Not implemented")
def test_example2(example_data):
assert aoc.part2(example_data) == ...
assert aoc.part2(example_data) == 1924
def test_part1(day04_data):
assert aoc.part1(day04_data) == 25023
@pytest.mark.skip(reason="Not implemented")
def test_part2(day04_data):
assert aoc.part2(day04_data) == ...
assert aoc.part2(day04_data) == 2634

Loading…
Cancel
Save