Riddler Classic: March 5, 2021

David Ding

March 5, 2021

Matching Baseball Numbers

Suppose a baseball player has four at-bats per game (not including walks), so their batting average is the number of hits they got divided by four times the number of games they played. For many games, it’s possible to have a corresponding batting average that, when rounded to three digits, equals the number of games divided by 1,000. For example, if a player typically gets one hit per game in their at-bats, then they could very well have a .250 average over 250 games.

What is the greatest number of games for which it is not possible to have a matching rounded batting average? Again, assume four at-bats per game.

Answer: 239 games for four at-bats per game.

Explanation:

Too lazy. I will use exhaustive search. Keep in mind that from the puzzle it is implied the maximum number of games is < 1000, as one cannot bat over 1.000.

   
 function maxGameNoMatch = getMaxGameNoMatch(absPerGame)
     % Given the at bats per game, determine the maximum number of games in
     % which the match is not possible.
     % This is done using exhaustive search.
     % Author: David Ding
    
     maxGames = 999;
     maxGameNoMatch = 1;

     for g = 1:maxGames
         found = false;
         ab = absPerGame * g;
         for chances = 1:ab
             stat = getRoundedBA(chances, ab);
             if stat == g
                 found = true;
                 break; 
             end
         end

         if ~found
             maxGameNoMatch = g;
         end
     end
end

function  stat = getRoundedBA(hits, ab)
    % Given the number of hits and ab, return stat which is your batting
    % average, rounded to three nearest decimal places after * 1000.
    
    rawStat = hits/ab;
    stat = round(rawStat * 1000);
end
		

Result:

   
>> maxGameNoMatch = getMaxGameNoMatch(4)

maxGameNoMatch =

   239
		

Extension

Assuming we are not limited to exactly four at-bats per game on average, how does our results of maximum games with no matching BAs change?

Here I am exploring a range between 2 to 6 at-bats per game. I don't think even Mike Trout can exceed six.

At-Bat Chart

The general trend is a negative correlation between the max game with no matching BA and the average ab-bat per game, which makes sense as the increments between successive batting averages decrease as the total number of at-bats increases. This makes it harder for BAs to not match the number of games as the latter increases. However, the decrease is not monotonic, as individual at-bat averages can fluctuate the result.