Java (JDK), 59 48 bytes
a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2
Returns an Object
, which is the Integer
0
for invalid games and the Boolean
s true
and false
for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.
-2 bytes
by inverting the end-of-match check.
-11 bytes
by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen
##Ungolfed
Ungolfed
a-> // Curried: Target type IntFunction<IntFunction<Object>>
b-> // Target type IntFunction<Object>
// Invalid if:
b<0 // Any score is negative
| b > 29 // Both scores above 29
| a > b + 2 // Lead too big
& a > 21 // and leader has at least 21 points
| a > 30 // Anyone has 31 points
? 0 // If invalid, return 0 (autoboxed to Integer)
// If valid, return whether the game is ongoing (autoboxed to Boolean)
// Ongoing if:
: a < 21 // Nobody has 21 points
| a < 30 // Leader has fewer than 30 points
& a < b + 2 // and lead is small