In the "100 game", two players take turns adding any integer from 1 to 10 to a running total, and the player who first makes the total reach or exceed 100 wins.
Now change the game so that players cannot reuse integers. The two players draw from a shared pool of the integers 1 to max_choosable_integer without replacement, adding each pick to the running total, and the first player whose pick makes the total reach or exceed desired_total wins. For example, the players might draw from the integers 1 to 15 until the total reaches at least 100.
Given max_choosable_integer and desired_total, return True if the first player to move can force a win, otherwise return False. Assume both players play optimally.
Function Signature
def can_first_player_win(max_choosable_integer: int, desired_total: int) -> bool:
Rules
-
The running total starts at 0 and the first player moves first. Players alternate, and each pick removes that integer from the pool for both players.
-
If
desired_total
is 0, the target is met before any move and the answer is
True
.
-
If the pool runs out before the total reaches
desired_total
, nobody wins and the answer is
False
.
Constraints
-
1 <= max_choosable_integer <= 20
-
0 <= desired_total <= 300
Examples
Input: max_choosable_integer = 10, desired_total = 11
Output: False
Whatever integer x the first player picks, the second player picks 11 - x. That value is between 1 and 10 and differs from x because 11 is odd, so it is still in the pool, and it brings the total to exactly 11.
Input: max_choosable_integer = 10, desired_total = 0
Output: True
The target is already met before anyone moves, so the first player wins.
Input: max_choosable_integer = 4, desired_total = 6
Output: True
The first player picks 1, leaving 5 to go with 2, 3 and 4 in the pool. No single pick covers 5. After the second player takes 2, 3 or 4, at most 3 is left to go while a larger or equal number is still in the pool, so the first player reaches 6 on the next turn.