This is a re-upload of an earlier video that had a small mistake
A puzzle with infinite probabilities
Subscribe for more puzzles
Python:
from random import random
trials = 0
count = 0
average = 0
for i in range(10**8):
trials += 1
n = 1000
running = True
while running:
n = int(random() * n) + 1
count += 1
if n == 1:
running = False
average = count / trials
if i % 10**6 == 0:
print(average)
JS (Credit to @cambrown5633; LaTeX notation for angle brackets):
function f() {
let n = 1000, c = 0;
while(n \gt 1)
n = Math.floor(Math.random()*n)+1
c++
}
return c
}
let s = 0
for (let r=0;r \lt 1000000;r++)
s += f()
console.log(s / 1000000)
#maths #probability #puzzles