Solution to problem 4 part 2 in Python

This commit is contained in:
David Doblas Jiménez 2022-02-05 18:53:55 +01:00
parent 79da60681c
commit f149966cd7

View File

@ -76,6 +76,7 @@
# To guarantee victory against the giant squid, figure out which board will win
# first. What will your final score be if you choose that board?
import queue
from typing import Tuple
with open("files/P4.txt", "r") as f:
@ -141,10 +142,28 @@ def part_1() -> None:
# Figure out which board will win last. Once it wins, what would its final
# score be?
# from collections import OrderedDict
# from copy import copy
def part_2() -> None:
numbers_drawn = []
winner = False
while not winner:
for number in numbers:
numbers_drawn.append(number)
if len(numbers_drawn) < 5:
continue
idx = 0
while idx < len(boards):
if has_won(boards[idx], numbers_drawn):
if len(boards) > 1:
boards.pop(idx)
else:
return print(
sum_board(boards[idx], numbers_drawn) * int(number)
)
else:
idx += 1
if __name__ == "__main__":
part_1()
# part_2()
part_2()