Solution to problem 4 part 2 in Python
This commit is contained in:
parent
79da60681c
commit
f149966cd7
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user