## Bouncing screensaver

We’ve all seen the bouncing screensaver. And we’ve all watched, hoping it would fall into the corner. Oh, you haven’t? Well, watch this documentary footage of the adventure you’ve been missing.

The screensaver isn’t mysterious. It moves in predictable ways, meaning we can calculate how often it’ll hit the corner (and if it will hit a corner). So let’s start with some assumptions.

• The bouncing object is smaller than the screen.
• It starts in the upper left hand corner.
• It moves at a 45 degree angle.
• It bounces perfectly (i.e. it always is moving at a 45 degree angle).

From this, we can make a few quick observations. The total distance it has traveled left and right is always equal to the total distance it has traveled up and down. And in order to land in a corner, it must have traveled a whole multiple of the both the width and the height of the screen. Or to put it mathematically:

We can find the lowest possible values for both m and n (which must be integers) fairly easily. The definition of the greatest common divisor of W and H implies that:

You can follow the same logic to calculate the value of m.

So now we know how many times the bouncing object travels the width of the screen (m) and the height of the screen (n). Each of those traversals will be followed by a bounce. We’ll need to subtract 1, because the last bounce – the impossible dream, the bounce in the corner – is counted as a horizontal and a vertical bounce. So the number of bounces necessary is:

Let’s find out how many times Jim and Pam and the others would have to watch the screen saver bounce to see it go into a corner. The DVD was most likely running at an effective resolution of 640x480 (equivalent to 480p). It’s hard to tell the size of the bouncing object, but it’s definitely smaller than a quarter of the height, plus it appears to have an non-bouncing border. Let’s eyeball it at 50x50. So:

Left as an exercise for the reader: Which corner will the object bounce in? Is it possible for the object to only bounce in the upper-left hand corner (where it starts)?

## Expected ERA

Imagine two hypothetical pitchers. Their ERAs are very close together and both pretty average: 3.40 and 3.41. They’ve both pitched just over 200 innings in 30 starts with just a couple weeks of the season remaining. But one pitcher has had some pretty advantageous matchups: he’s played the Padres four times, the Reds and Rockies twice each, the Pirates, the Mets, the Royals – all teams with records under .500. The other pitcher, on the other hand, has had a harder schedule: four games each against the Yankees and the Red Sox, two against the Rangers, and one in Detroit. Are these equivalent pitchers?

I set out to determine if pitchers we accept as “elite” are truly that great, or if some might have an unfair advantage due to schedules. I downloaded all of MLB’s gamelogs for the 2011 regular season up through yesterday, and then I parsed them, tracking a few key pieces of information. First, the number of innings each pitcher pitched against each team. Second, the average number of earned runs each team scores per inning. Then, for each pitcher, I calculated what their ERA would be if they allowed exactly their opponent’s average for each appearance. Here are the results (for pitchers who have enough innings pitched to qualify for the ERA title):

Expected ERA - after 2011-09-12

One interesting takeaway is that there aren’t any huge surprises. Of the pitchers with the ten best actual ERAs, only one of them (Cole Hamels) isn’t in the top ten for the best differential. Another interesting fact is how much a pitcher’s expected ERA is affected by simple rotation timing, and not just the team’s schedule. The Phillies have played against a lot of sub-.500 teams this year, and Cole Hamels has one of the lowest expected ERAs. But his teammate Cliff Lee hasn’t been so lucky – his expected ERA is higher than most.

But there are some people who get a nudge from good to great with this analysis. Oh, and those two hypothetical pitchers I mentioned? They aren’t hypothetical. They’re Daniel Hudson of the Diamondbacks and David Price of the Rays, respectively. This puts a little context on the fact that Price’s record is 12-12 and Hudson’s is 16-9.

## Solitaire probabilities

For some reason, I’ve been thinking about Klondike solitaire probabilities a lot lately. Primarily, I’m wondering what the likelihood is that a game will have zero legal plays. I’m certain it happens, but it’s got to be pretty rare. It’s a complex game, though, so here’s my plan towards solving it:

1. Given two non-ace cards, what is the chance that one cannot be placed on the other, using standard Klondike rules?
2. Given three non-ace cards, what is the chance that none can be played on any other?
3. Given seven...?
4. Given two (three, seven) cards, what is the chance that there is no legal play (placing one on another or moving an ace to the foundation)?

There are more steps after that involving the eight deck cards, but it gets pretty complicated pretty quickly. I’ll be happy just getting this far.