Problem 56523. Cricket - Sort Batters by Distance Run

Given a string vector of batters' names, a vector of the total number of runs they scored, a vector of the number of 4s they scored, and a vector of the number of 6s, return a string array of the player's names sorted according to how far they actually ran for their runs, from farthest to least. You can assume that 4s and 6s were not run at all (so the problem is equivalent to sorting according to the number of runs scored not from boundaries).
For example,
Table showing runs, fours, and sixes for three batters. Matt has 6 runs, 0 fours, 0 sixes. Ben has 18 runs, 2 fours, 0 sixes. Renee has 20 runs, 3 fours, 1 six.
name = ["Matt";"Ben";"Renee"];
runs = [6;18;20];
fours = [0;2;3];
sixes = [0;0;1];
sortednames = sortbyrundistance(name,runs,fours,sixes)
sortednames =
3×1 string array
Here, Matt has run 6 runs, Ben 10 (8 of his total 18 came from 4s), Renee 2 (18 of her 20 runs came from boundaries).
A batter's score is the total of runs physically run and runs scored from boundaries (hitting the ball to the boundary scores an automatic 4 runs, hitting it over the boundary scores an automatic 6 runs). The score is typically reported as the total runs scored, along with the number of boundary 4s and 6s. In the above example, Ben's score is 18 runs (total), including 2 4s and 0 6s. Hence, his score was 10 runs he actually ran, plus 8 runs from boundaries.

Solution Stats

55.69% Correct | 44.31% Incorrect
Last Solution submitted on May 28, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers73

Suggested Problems

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!