Draft

The Hope Function

Description:

Suppose you believe that a piece of treasure is hidden in one of n boxes. Before you start looking, you estimate there is probability p that the treasure is in any of the boxes at all. As you open more and more of the boxes, what happens to the probability that the treasure is in the next box you'll open? And what is the probability that the treasure will be in any of the remaining boxes at all?

Please note: the harder part of this problem is the maths/probability side, rather than the coding/implementation side. If you'd like to skip ahead to implmementation, you can implement the formulas given here.

Given p (the prior probability that the treasure is in any of the boxes, n (the total number of boxes) and i (the number of boxes you have already searched without finding the treasure), return a list with two elements: the probability that the treasure will be in the next (i+1th) box, and the probability that the treasure will be in any of the remaining boxes at all.

Assume at all times that, if the treasure is there at all, it's equally likely to be in any of the remaining boxes.

Note: to tolerate floating point error, the tests use approx_equals with margin 1e-02

More By Author:

Check out these other kata created by marbiru

Stats:

CreatedApr 6, 2019
Warriors Trained11
Total Skips0
Total Code Submissions22
Total Times Completed3
Python Completions3
Total Stars0
% of votes with a positive feedback rating0% of 1
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes1
Total Rank Assessments2
Average Assessed Rank
8 kyu
Highest Assessed Rank
8 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • marbiru Avatar
Ad