Toll Lanes: Behavior Hypothesis
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Description
While examining data from the last exercise, you noticed that cars passing through your checkpoint made interesting choices about which lane line to enter. Your coworker has a hypothesis: that cars always choose to arrive at a lane which had the shortest line (or one of the shortest lines, if there's a tie) at the beginning of the minute, regardless of what other cars choose. In other words, she thinks that drivers are smart and perceptive, but not cooperative!
lane_lines = [[0, 0, 0],
[1, 1, 0],
[0, 0, 2],
[2, 3, 1]]
In the running example copied above, her hypothesis holds:
- During the first minute, cars can arrive to any of the three lanes according to the hypothesis, since all were equally short at the beginning of the first minute.
- During the second minute, cars can only arrive in the third lane accoring to the hypothesis, since that was the shortest line at the beginning of the second minute. Indeed, cars only arrive in the third lane.
- During the third minute, cars can arrive in the first or middle lane according to the hypothesis, since those were the shortest lines at the beginning of the third minute. This holds as well.
Answer the below question without writing code, then view our answer and explanation, to check your understanding.
lane_lines2 = [[3, 0, 2],
[2, 1, 1],
[2, 2, 2],
[9, 1, 1]]
lane_lines2
?
Your Task
Write a function hypothesis_holds(lane_lines)
to check whether your coworker's hypothesis holds. Return True
if it holds (during every minute in the data), and False
otherwise.
Code Submission
Once you have tested your code on your own machine, upload it below:
Next Exercise: Toll Lanes: Simulation