Frog jump problem

In [1]:
from IPython.display import YouTubeVideo

YouTubeVideo('ZLTyX4zL2Fc')
Out[1]:
In [2]:
import random
import numpy as np
In [3]:
%%time
simulations = 1000000
sim_counter = 1
jumps_list = list()

while sim_counter <= simulations:
    current = 1
    last = 10
    jumps = 0

    while current < last:
#         print("Current: {}".format(current))

        choice = random.randint(1, last-current)
#         print("Choice: {}".format(choice))
        current += choice
        jumps += 1

#         print("Jumped to: {}".format(current))
#     print("Jumps: {}".format(jumps))
    
    jumps_list.append(jumps)
    sim_counter += 1
    
# print("Jumps: {}".format(jumps_list))
print("Jumps: {}".format(np.mean(jumps_list)))
Jumps: 2.829268
CPU times: user 14.3 s, sys: 38 ms, total: 14.4 s
Wall time: 14.4 s

by Wojciech Wiertarka