Thursday, March 6, 2014

A maths/math/physics question

So I'm watching season 1 of The Killing on Netflix.  The show is great by the way, if you're into suspenseful murder mystery type stuff.  Of course they mislead you in 15 different directions only to each time stomp out all your suspicions and provide a near perfect alibi for your most recent suspect.  I still haven't finished season 1, but I'm going at my own pace, so NO SPOILERS please.  You won't find them in this blog, so I'd appreciate not finding them in the comments...

Anyhow, in Season 1 detective Holder is joking around reading a math question out of a school algebra book.  It goes something like this:

Holder: A biker goes blah blah distance at 8 miles per hour and then the same fool he bikes back at 10 miles per hour.  So what's the average round trip rate?
Jack: I don't know
Holder: And I don't give a shit.
I'm assuming the majority of you are in the same camp as Jack and/or Holder (don't know, don't care).  I however, am not, and I love math, almost as much as I love drinking!  OK, I lied, I love math more, but that's kind of scary to some people, so I'll stick with my original stance.

Anyhow, I had this drunken conversation with my brother last night, who I made watch the first 3 episodes, and we agreed, the answer, just like the killer in the show, is not the obvious suspect, which would be 9 miles per hour, or at this point, Jasper.  In order to calculate the correct answer, I quickly wrote up a few lines of python to determine the correct answer, while my brother was trying to think of extreme cases, such as what if you change the problem from 8 and 10 to say 1 and 60?

So, here's the sloppy python code I wrote up:

import sys
try:
    speed1 = int(sys.argv[1])
except:
    speed1 = 8.0
try:
    speed2 = int(sys.argv[2])
except:
    speed2 = 10.0
# speed in mph
time1 = 1.0 / speed1
time2 = 1.0 / speed2
avg = 2.0 / (time1 + time2)
print(avg)
Running the script with no parameters tells us that the answer is 8.88889 miles per hour.  It's a bit counter-intuitive, until you start to think in terms of extremes.  Running the script with 1 and 60 as the speeds, a person might expect an average somewhere near 30, however, that would be pretty far from accurate.  In fact, running the script as such:

python avg_speed_same_distance.py 1 60
1.96721311475
It's not even over 2 miles per hour.  In fact, if you ride the first leg of the trip at 1 mile per hour, you can NEVER make the round trip over 2 miles per hour.  Take the most extreme case you can think of, where you traverse the reverse trip in 0 time, basically you travel at infinity miles per hour, you will still only have averaged 2 miles per hour.  For instance, you travel 1 mile at 1 mile per hour, that's exactly 1 hour.  Now, turn around, and instantly complete the reverse trip.  Now you've traveled 2 miles, but it still took you an hour, so the round trip average is 2 miles per hour.

Just to assure myself that the distance was irrelevant, I changed up the code, so that the distance is just randomly chosen on each run of the script.

import random
import sys
distance = random.randint(1, 1000)
try:
    speed1 = int(sys.argv[1])
except:
    speed1 = 8.0
try:
    speed2 = int(sys.argv[2])
except:
    speed2 = 10.0
# speed in mph
time1 = distance / speed1
time2 = distance / speed2
avg = (distance * 2.0) / (time1 + time2)
print(avg)
As I suspected, it doesn't matter, you get the same results for the same parameters, every time, even with varying distance.

TLDR; The answer is C.  The answer is always C.