Skip to main content
2 of 5
added 418 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:0!=a/30or cmp(b,2+max(19,a)-a/29)

[Try it online!][TIO-jtqhdtff]

[TIO-jtqhdtff]: https://tio.run/##jZbNbuNGEITvfgrmZBmRsKyeH84s4EOA3UOAIMdcHB/o2FIE2LLhGEH26R2qq8aUmATIpY2mNfU1yanivHx7@/35YO/b61/fH8enu/uxG9d3n/vvrsdPoX9@7X57elndre37p/GvFep6vNqMn6xevV@8vO4Pb93ln@Pj/r57ONw/3H@@1MXtquvXneHqo4ed94apDyd9WXehP@kr@3PK/tC9PI7fFpzuZJ1z@3MubMFdzmEzZ39w0glhc/wJ6rxkMz2FM41uc/zF4l5tcS8n/w/9@b3G6ffx5Fmgd2R/ZPDixS8//PTjl@ubm37d366nCq/mNXiNXpPX7HXwWrxWrtJirgaXg@tBAVABlAA1QBFQxahiRxWsWc1r8Bq9Jq/Z6@C1eK1c1fOPNLgcXA8KgAqgBKgBioAqRhWfxHwG8xnMZzCfwXwG8xnMZzCfwTiDcQbjDMYZjDMYZzDOYJzBOINxBuMMxhmC04PTg9OD04PTg9OD0wPpgfRAeiA9kB5ID6QH0gPpgfRAeiA9Ojc6Nzo3Ojc6Nzo3khvJjeRGciO5kdxIbiQ3khvJjeRGcpMT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vziF8uLe/AQ "Python 2 – Try It Online"

Outputs:

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