Project Euler 697 - Randomly Decaying Sequence

Official link: https://projecteuler.net/problem=697

Note: This problem is not suitable for hints!!

Thought Process

Note: This problem is not suitable for hints!!


This problem was quite fun to solve, and I am lucky I took a statistics class last year.

Below are the main 2 facts that you need to solve this problem

  1. https://en.wikipedia.org/wiki/Continuous_uniform_distribution#Related_distributions

  2. https://en.wikipedia.org/wiki/Exponential_distribution#Sum_of_two_independent_exponential_random_variables

With this we can begin to solve the problem

Step 5 is the crucial step, we make use of (1) by recognising that -ln(U_i) ~ Exp(1) and (2) by recognising that is this is just a sum of 10,000,000 exponential variables. Initially I solved this problem using an online tool (https://homepage.divms.uiowa.edu/~mbognar/applets/gamma.html) and then dividing it by ln(10) (because our answer will be in the form ln(c)), but found an python function (https://docs.scipy.org/doc/scipy/reference/reference/generated/scipy.stats.gamma.html#scipy.stats.gamma) which does the job!

Interactive Code

Enter a number (yourinput)

Code will output log_10(c) given that P(X_yourinput < 1) = 0.25