Python 2, 47 bytes
lambda a,b:[61>60-a>b<3+max(19,a)for b in-~b,b]
Outputs a list of two Booleans. Thanks to TFeld for writing a test suite in their answer that made it easy to check my solution.
ended: [False, True]
going: [True, True]
invalid: [False, False]
The key insight is that a valid score ends the game exactly if increasing the higher value b
makes the score invalid. So, we just code up the validity condition, and check it for (a,b+1)
in addition to (a,b)
to see if the game has ended.
Validity is checked via three conditions that are chained together:
b<3+max(19,a)
: Checks that the higher scoreb
isn't past winning, with eitherb<=21
orb<=a+2
(win by two)60-a>b
: Equivalent toa+b<=59
, ensuring the score isn't above(29,30)
61>60-a
: Equivalent toa>=0
, ensures the lower score is non-negative
Python 2, 44 bytes
lambda a,b:[b-61<~a<a>b/22*b-3for b in-~b,b]
An improved validity check by TFeld saves 3 bytes. The main idea is to branch on "overtime" b>21
with b/22*b
which effectively sets below-21 scores to zero, whereas I'd branched on a>19
with the longer max(19,a)
.
Python 2, 43 bytes
lambda a,b:a>>99|cmp(2+max(19,a)%30-a/29,b)
Outputs:
ended: 0
going: -1
invalid: 1
Assumes that the inputs are not below \$-2^{99}\$.