code: def findBinomialNsWithExpectedSampleMinimum(desiredValuesSorted, p, numSamples, nMax):
    
  
    # mapping from n -> expected value
    actualValues = [
      getExpectedValue(
        SampleMinimumDistribution(numSamples,
                                  BinomialDistribution(n, p, cache=True)))
      for n in xrange(nMax + 1)]
  
    results = []
  
    n = 0
  
    for desiredValue in desiredValuesSorted:
      while n + 1 <= nMax and actualValues[n + 1] < desiredValue:
        n += 1
  
      if n + 1 > nMax:
        break
  
      interpolated = n + ((desiredValue - actualValues[n]) /
                          (actualValues[n+1] - actualValues[n]))
      result = (interpolated, actualValues[n], actualValues[n + 1])
      results.append(result)
  
    return results
docs: For each desired value, find an approximate n for which the sample minimum
    has a expected value equal to this value.
  
    For each value, find an adjacent pair of n values whose expected sample minima
    are below and above the desired value, respectively, and return a
    linearly-interpolated n between these two values.
  
    @param p (float)
    The p if the binomial distribution.
  
    @param numSamples (int)
    The number of samples in the sample minimum distribution.
  
    @return
    A list of results. Each result contains
      (interpolated_n, lower_value, upper_value).
    where each lower_value and upper_value are the expected sample minimum for
    floor(interpolated_n) and ceil(interpolated_n)