Problem 56538. Cricket - Report the Result (Part II: Test Matches)
- "Match drawn"
- "TeamName won by n runs"
- "TeamName won by n wickets"
- "TeamName won by an innings and n runs"
- Test matches are played over a fixed time period. If the match is not completed in that time, the result is a draw (regardless of the score).
- To avoid running out of time (thus resulting in a draw), a team can choose to declare their innings completed before they are all out. This is effectively a gamble to forfeit the remainder of their innings for the sake of time.
- After both teams' first innings, if Team B is sufficiently far (200+ runs) behind Team A, A can choose to make B follow-on, meaning Team B has to bat again immediately, while Team A can keep their second innings in reserve if needed. Hence, the order of innings is A, B, B, A (if necessary), instead of the usual A, B, A, B.
- Team A scores 543 and declares with 4 wickets still in hand
- Team B scores 234 (all out)
- Team B, forced to follow-on (309 runs behind), scores 456 and declares with 3 wickets in hand, giving A a target of 148 to win
- Team A scores 123 for the loss of 4 wickets, leaving them 24 runs behind Team B's total
Solution Stats
Problem Comments
-
9 Comments
This problem's description may not be correct. I could fit my code into the test suite (guessing rules). However, I needed more than following the problem's description to succeed. For instance, I thought that the existence of /w or (f/o) was a requirement for a team to be declared a winner, but not necessarily; exceptions exist to this rule. This problem's author probably assumed that we know the rules for scoring in cricket and the problem is not self-contained. I was able to maybe guess the rules correctly, but it made the problem way harder than it was supposed to be (Schröder, the other user able to solve this problem so far, had to guess too).
My tip is to follow the problem's description exactly, then try to remove some rules until your code passes the test suite. It was basically what I did. That's why I am unsure whether the description is correct or the author is making some assumptions about our cricket knowledge. Specifically, one problem that I found is what to do whenever the flag /d is found (I will read more about cricket later, but if any expert is present, please let us know).
@Rafael You're correct: I had to take a look at the test suit and attempt to attempt to divine the scoring rules for crickets in order to be solve this, too.
But hey, I learned something (about cricket if nothing else), and sometimes, that's half the fun!
Thanks, Rafael for all your feedback. It's helpful to get a "cricket outsider's" insights. The last two problems of the set were intended to be challenging, and it's blowing my mind that the first two people to finish them did so with no cricket knowledge! Well done.
I'm trying to walk a line between not giving enough information and making it impossible for those who don't have the cricket background, and giving too much information and thus giving away the solution. In this problem, use the table as your guide to determining results (other than a draw). Notice that declarations don't appear in the table - they don't have any effect on the result. I mentioned them in the problem description because I didn't want people to make assumptions about the formatting (like: the scores will always end with a numeric digit) and base their string/regexp/pattern approach on those incorrect assumptions. Follow-ons change the order of the innings, so do have some effect - again, follow the table - but there's no requirement that either declarations or follow-ons occur. See the first code example for one that has nothing but simple scores.
It's entirely possible that something in my description is incorrect or misleading. The test cases are all real matches, so they are correct. If you think a test case doesn't match the description, let me know and I can either correct the description or add some explanation. (The conventions here *are* weird. That's cricket for you.)
Tip: you can ignore ties, so you can get the total scores for both teams and one will be higher than the other. That gives you a "provisional winner" and "loser". That's when the last paragraph (about a result vs a draw) kicks in: unless the "losing" team has completed both innings, it's a draw. That means you need to figure out a way to tell if that has happened. (Hint: the first innings must have been completed if there's a second one; the second innings would only be completed if all 10 wickets have been taken*). If it's not a draw, then the result will be one of the options in the table.
[*] A declaration also completes the innings, but declaring your second innings while you're still losing would be suicide, so that will never occur. Hence, a (non-draw) result occurs only if the "losing" team is all out in their second innings. How to figure out if a team is all out is given in the second paragraph.
I read a little more about the game's rules, and I understand it a little more. I learned a lot from this problem group :). For instance, (f/o) means that the team losing has to play, changing the order in which the teams would play (I initially was confused about how the order could be changed). Declared innings mean that team has stopped playing because the team's captain is confident they will win or because they think there is no chance of winning. So it affects the result because /N (N being the number of lost wickets) means the team is still playing. At least that's what I've gathered from test #11, when England wins. According to the table, the string should have been England wins by 10 wickets, but the test suite claims England won by 18 runs since the game ended, or they have lost no wickets. Another issue is test #2, in which India clearly has enough points to win. However, we cannot declare a winner since Australia is still playing and has lost 0 wickets.
And thanks for all these problems, they were fun. :)
@Matt it's funny that you say that declarations don't affect the result while follow-ons do --- in my solution, it's just the opposite, I take declarations into account but found that I could ignore follow-ons.
Also, I agree with @Rafael: these problems were fun indeed. Well done, and thanks for the entire set. :)
"The test cases are all real matches, so they are correct", I said overconfidently, overlooking my ability to make stupid copy-paste errors! :)
Thanks again, Rafael for helping find that bug in the tests. You're right that #11 is incorrect - I left off the "(f/o)" on England's second innings. Without it, the score doesn't make any sense because England had more runs, but are all out in what would be the 4th innings, which is impossible. I'll update the test but won't rescore the solutions, so your answers will stand as correct (I don't want to risk breaking your hard work for my mistake).
Your interpretation of test #2 is correct. India batted once. Australia is behind on runs but their second innings is still in progress, so it's a draw.
@Christian: you're right that if you assume the scores have been recorded correctly, you don't need to look for the follow-ons for the MATLAB to work correctly. If you're looking to figure out if an innings is completed, then the "d" after the "/w" is important - I'm guessing that's what you used it for. But you can also shortcut that. When I said declarations don't affect the result, I meant the way the result is reported ("n wickets" or "n runs") - in the table, "___" could mean 123 or 123/4d.
Glad you enjoyed the problems, despite not understanding the subject matter! Maybe that was part of the challenge?
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
27374 Solvers
-
Cell Counting: How Many Draws?
1870 Solvers
-
Rule of mixtures (composites) - lower and upper bounds
67 Solvers
-
Rule of mixtures (composites) - weighted bound
71 Solvers
-
Coefficient of Kinetic friction
192 Solvers
More from this Author22
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!