Clean up day04 part 1

This commit is contained in:
Thom Dickson 2021-12-04 22:42:56 -05:00
parent 8856fe38f8
commit 142c4dd69b
Signed by: boots
GPG Key ID: 40BE2AF8EBF8D2BB
2 changed files with 18 additions and 27 deletions

View File

@ -600,4 +600,3 @@
53 79 89 32 14 53 79 89 32 14
55 63 50 7 62 55 63 50 7 62
EOF

View File

@ -42,37 +42,29 @@ def ingest(input):
def part1(): def part1():
input_seq = []
boards = []
with open("day04.in", "r") as f: with open("day04.in", "r") as f:
input_seq = [int(x) for x in f.readline().rstrip().split(",")] input_seq, boards = ingest([line for line in f])
f.readline()
boards = []
line = f.readline()
while line != "EOF\n":
board = []
while line != "\n":
board.append([int(x) for x in line.rstrip().split()])
line = f.readline()
boards.append(board)
line = f.readline()
checked = [[[0 for i in row] for row in board] for board in boards] checked = [[[0 for i in row] for row in board] for board in boards]
score = 0 score = 0
for num in input_seq: for num in input_seq:
for board in range(len(boards)): for board in range(len(boards)):
for row in range(len(boards[board])): for row in range(len(boards[board])):
for cell in range(len(boards[board][row])): for cell in range(len(boards[board][row])):
if boards[board][row][cell] == num: if boards[board][row][cell] == num:
checked[board][row][cell] = 1 checked[board][row][cell] = 1
win_board = get_win_board(boards, checked) win_board = get_win_board(boards, checked)
if win_board is not None: if win_board is not None:
score = calc_score(boards[win_board], checked[win_board], num) score = calc_score(boards[win_board], checked[win_board], num)
break break
print("Winning score:", score) print("Winning score:", score)
def part2(): def part2():
input_seq = None input_seq = []
boards = None boards = []
with open("day04.in2", "r") as f: with open("day04.in2", "r") as f:
input_seq, boards = ingest([line for line in f]) input_seq, boards = ingest([line for line in f])
print(input_seq) print(input_seq)