This question evaluates a candidate's ability to perform simulation-based probabilistic estimation, sample and aggregate historical per-obstacle times, and correctly handle incomplete run records within a collection.
You are given a simplified model for tracking race times on an obstacle course.
For an obstacle index i, the historical times available for that obstacle come from all other runs that reached obstacle i, including incomplete runs.
Implement the method chance_of_personal_best(run) in RunCollection.
Given an in-progress run:
Suppose a course has 3 obstacles and the historical runs are:
[3, 3, 2]
[3, 3, 3]
The current in-progress run is [3, 3].
The personal best among completed runs is 8.
For the last obstacle, the historical times are {2, 3}.
So the simulated completed run is either [3,3,2] or [3,3,3], each with equal probability.
Therefore the chance of matching or beating the personal best is about 0.5.
Assume classes similar to the following already exist:
Course(title, obstacle_count)
Run(course)
with fields:
course
complete
obstacle_times
add_obstacle_time(t)
get_run_time()
RunCollection(course)
with field:
runs
Write the chance_of_personal_best method for RunCollection.