Determine the Winner of a Bowling Game
This problem requires us to compare the scores of two players in a bowling game. Each player has the same number of turns and the number of pins hit by each player in each turn is known. The score for a turn is twice the number of pins hit in that turn if the player hit all 10 pins in any of the previous two turns, otherwise, it is the number of pins hit in that turn. The total score is the sum of the scores for all turns.
We can solve this problem by first computing the total scores for both players and then comparing the scores to determine the winner.
Here is the Python code:


This code first initializes two lists, scores1 and scores2, to store the scores for each turn for both players. Then it computes the scores for all turns for both players according to the rules of the game. Finally, it computes the total scores for both players and compares them to determine the winner. If player1’s total score is higher, it returns 1, if player2’s total score is higher, it returns 2, if both total scores are equal, it returns 0.