Skip to main content
3 of 5
deleted 406 characters in body
xnor
  • 146.6k
  • 26
  • 279
  • 652

Python 2, 47 bytes

lambda a,b:[61>60-a>b<3+max(19,a)for b in-~b,b]

Try it online!

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 score b isn't past winning, with either b<=21 or b<=a+2 (win by two)
  • 60-a>b: Equivalent to a+b<=59, ensuring the score isn't above (29,30)
  • 61>60-a: Equivalent to a>=0, ensures the lower score is non-negative

Python 2, 44 bytes

lambda a,b:a<0 or cmp(b,2+max(19,a)%30-a/29)

Try it online!

Outputs:

ended: 0
going: -1
invalid: 1 (including True)
xnor
  • 146.6k
  • 26
  • 279
  • 652