Background
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)
. - Person
A
serves for 5 points, then PersonB
serves for 5 points, then back toA
. Hence,A
serves whenever the total scoreA+B
is0-4
mod 10. - After each serve, either
A
scores a point orB
scores a point.A
andB
both start with0
points. - 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)
Task
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.
Examples
Given (4,5), (1,4)
, the output should be truthy. The example game is one where this score set occurs.
Given (4,2), (3,5)
, the output should be falsey. They occur at point totals 6
and 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 4
to 3
while A
's score increases from 2
to 5
, so this situation is impossible.
Given (3,1), (1,5)
, the output should be truthy. (3,1)
is reported as (A,B)
, while (1,5)
is reported as (B,A)
, so the game can transition from (3,1)
to (1,5)
if A
scores 2
points.
Test Cases
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)
0-4 (mod 10)
. \$\endgroup\$