In the sport of Table Tennis (aka Ping-Pong or Whiff Whaff), two opponents play a sequence of rounds, where each round consists of players hitting a ball back and forth until one player (may or may not be the server) gains a point.
Table Tennis has some official rules that make for a good game, but we will use a different set of rules for a better challenge.
The modified rules are as follows:
- The score is announced directly before each serve as a pair
(current server's score, other player's score).
Aserves for 5 points, then Person
Bserves for 5 points, then back to
Aserves whenever the total score
- After each serve, either
Ascores a point or
Bscores a point.
Bboth start with
- For simplicity, games never end.
Following is an example game:
(A starts serving, so the scores are read as (A,B)) 0,0; A scores a point 1,0; B scores a point 1,1; A scores a point 2,1; A scores a point 3,1; A scores a point (B is now serving, so the scores are read as (B,A)) 1,4; A scores a point 1,5; B scores a point 2,5; B scores a point 3,5; B scores a point 4,5; B scores a point (A is now serving, so the scores are read as (A,B)) 5,5; B scores a point 5,6 … (game continues)
Given a pair of unique score readouts, determine if they can be announced in the same game.
Your program/function may take input as any reasonable way equivalent to an ordered pair of numbers.
The output can follow your language's convention for truthy/falsey or use any two distinct values to represent true/false.
(4,5), (1,4), the output should be truthy. The example game is one where this score set occurs.
(4,2), (3,5), the output should be falsey. They occur at point totals
8 respectively, so
B is serving in both readouts, so both are reported as
(B,A). It is impossible for
B's score to decrease from
A's score increases from
5, so this situation is impossible.
(3,1), (1,5), the output should be truthy.
(3,1) is reported as
(1,5) is reported as
(B,A), so the game can transition from
Truthy: (4,5), (1,4) (3,1), (1,5) (0,0), (0,1) (0,0), (45,54) (6,9), (11,9) Falsey: (12,5), (11,6) (4,2), (3,5) (3,3), (5,2) (2,1), (4,1) (17,29), (17,24)