On the other hand, it might be wise to try a different strategy: let the giant squid win.
You aren’t sure how many bingo boards a giant squid could play at once, so rather than waste time counting its arms, the safe thing to do is to figure out which board will win last and choose that one. That way, no matter which boards it picks, it will win for sure.
In the above example, the second board is the last to win, which happens after 13
is eventually called and its middle column is completely marked. If you were to keep playing until this point, the second board would have a sum of unmarked numbers equal to 148
for a final score of \(148 \times 13 = 1924\).
Figure out which board will win last. Once it wins, what would its final score be? Determine this in the following way:
score
that takes the pathname (string
) of a text file containing a random order in which to draw numbers and a random set of boards. The function must return the score of the last board to win.In this interactive session we assume the text files boards01.txt
1 and boards02.txt
2 to be located in the current directory.
> score("boards01.txt")
1924
> score("boards02.txt")
9576
Jari Komppa (@Sol_HSA3) animated his solution.