So in my almost daily tiny basketball workout, i do this simple routine. i try to make 10 concecutive shots from the low post mark, just outside the key. then 5 at the next rebounder line, 3 at the elbow and 1 at the three. then 10 fullcourt layups to finish it up. this usually takes about 15 min, but once it was taking a pretty long time. so i was wondering if i make a shot with probability p, how many times do i need to try to make n consecutive shots?

this is still a little bit vague, we can make the question more concrete by asking for the expected n (mean), and the n that i succeed 50% of the time (median).

this is like tossing a biased coin/dice. the expected number of times to get a head (probability p being head) is 1/p. e.g. the mean number of times between tossing 2 sixes on a fair dice is 6 = 1/(1/6) =q(1+2p+3pp+…) where p=1/6, q=5/6. you get this by summing up the series or arguing by common sense, or by contradiction.

now, if i want to get 10 in a row, and say i have shooting percentage p=0.5. it would take me 10*1024 times to reach my goal on average if i insist on dividing my shots to these blocks of 10, and finishing each block even if i missed the first one. so in reality it doenst take this long. we can also think of it in variable sized blocks like these:

0, 10, 110, 1110, etc. and 1111111110

the expected length of these blocks is calculated like the above, but truncated after 10 terms. so, the expected length is just under 2 (the full summation would be 2 for p =0.5), and about 2.6 if p=0.9.

every sequence can be coded in these blocks. so the expected number of these blocks i need is 1/(p^n). with an average length of about 2. so i need 2/(p^n) tries on average this works out to be 2000 if i shoot 50%, about 30 times if i shoot 80% and only 18 times if i shoot 90%.

but mean is a little misleading, what about the median? well, here i need to find m so that (1-p^n)^m > 0.5. and multiply m by the average length. so here for p=0.5, m=710, for p=0.8, m=6, and for p=0.9, m=1.6. this gives us median number of shots of 1430, 20, and 14. notice how median < mean. in half of the time, i can finish shooting under 20 shots if i shoot with probabily 0.8

this calculation can be turned in reverse: another application is i can just count the number of attempts that i failed (111110 is counted as one single attempt) instead of counting the total number of shots, which is much bigger number. and use it to estimate my p. so this would be 1000 tries if i shoot 50%, 7 attempts if i shoot 80% and 3 times if i shoot 90%. the estimator obviously will have worse variance.

now a true scientisit will check his calculations, but being the programmer that i am i just wrote this script to confirm my results:

```M=100000; igettired=500;
alltries = igettired*ones(M,1);
p = 0.9;
for m = 1:M
seq = rand(igettired,1)<p;
for i = 10:igettired
for j = 0:9
if ~seq(i-j)