From 142c4dd69bbf6673987a8172d7e2ea7cfd3423db Mon Sep 17 00:00:00 2001 From: Thom Dickson Date: Sat, 4 Dec 2021 22:42:56 -0500 Subject: [PATCH] Clean up day04 part 1 --- day04.in | 1 - day04.py | 44 ++++++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/day04.in b/day04.in index 6ed60fe..1f00621 100644 --- a/day04.in +++ b/day04.in @@ -600,4 +600,3 @@ 53 79 89 32 14 55 63 50 7 62 -EOF diff --git a/day04.py b/day04.py index def33c5..8008568 100644 --- a/day04.py +++ b/day04.py @@ -42,37 +42,29 @@ def ingest(input): def part1(): + input_seq = [] + boards = [] with open("day04.in", "r") as f: - input_seq = [int(x) for x in f.readline().rstrip().split(",")] - 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() + input_seq, boards = ingest([line for line in f]) - checked = [[[0 for i in row] for row in board] for board in boards] - score = 0 - for num in input_seq: - for board in range(len(boards)): - for row in range(len(boards[board])): - for cell in range(len(boards[board][row])): - if boards[board][row][cell] == num: - checked[board][row][cell] = 1 - win_board = get_win_board(boards, checked) - if win_board is not None: - score = calc_score(boards[win_board], checked[win_board], num) - break - print("Winning score:", score) + checked = [[[0 for i in row] for row in board] for board in boards] + score = 0 + for num in input_seq: + for board in range(len(boards)): + for row in range(len(boards[board])): + for cell in range(len(boards[board][row])): + if boards[board][row][cell] == num: + checked[board][row][cell] = 1 + win_board = get_win_board(boards, checked) + if win_board is not None: + score = calc_score(boards[win_board], checked[win_board], num) + break + print("Winning score:", score) def part2(): - input_seq = None - boards = None + input_seq = [] + boards = [] with open("day04.in2", "r") as f: input_seq, boards = ingest([line for line in f]) print(input_seq)