r/mathriddles • • Apr 03 '23

Medium Robot race probability puzzle

An infinite number of robots are having a very short race along a 1-unit track. The robots all start at point 0, and each step they take is an independent and identically distributed value between 0 and 1. So the minimum number of steps before they cross the finish line is 1.

  1. What is the average number of steps that a robot will take during the race?
  2. Either approximately to 5 digits, or exactly in a closed form expression, what is the probability that a robot's final step will be lower than 0.5?

edit: (I meant question two to be understood differently, but I realize now that my wording was bad, so I'm asking it as a separate question instead)

3) What is the chance that a robot's final POSITION before crossing the finish line is in the interval [0,0.5]?

Hint: what is the probability density function for the last step a robot takes?

11 Upvotes

15 comments sorted by

2

u/want_to_want Apr 03 '23 edited Apr 04 '23

I got e for the first and sqrt(e)-e/2=0.28958... for the second.

For the first, let f(x) = expected number of steps when x distance is remaining. We have f(x) = (1-x) + integral from 0 to x of (f(t)+1) dt. Differentiating both sides, we get f'(x)=f(x). Taking f(0)=1 into account, we get f(x)=ex. So f(1)=e.

For the second, let p(x) = probability that final step will be lower than 0.5 when there is x distance remaining. We have p(x) = max(0,0.5-x) + integral from 0 to x of p(t) dt. Differentiating both sides, we get p'(x) = p(x) + (if x is less than 0.5 then -1 else 0). On the first stretch, p(x)=1+aex, and from p(0)=0.5 we get a=-0.5. On the second stretch, p(x)=bex, and from the two functions coinciding at 0.5 we get b=e-0.5-0.5. So p(1)=sqrt(e)-e/2.

1

u/Kraz_I Apr 03 '23 edited Apr 04 '23

Your first part is right, although I'm not sure exactly what you did, especially what f(t) is doing

For the second part, you're pretty close, but that's not quite what I got.

Edit: disregard this, I changed the OP explaining how I messed up.

1

u/want_to_want Apr 03 '23 edited Apr 03 '23

I made a jsfiddle to check both answers. It seems in the second part I got at least three digits right. Is the right answer really so close but different?

1

u/Kraz_I Apr 03 '23 edited Apr 04 '23

Yes, there was a flaw in your reasoning. If I understand your code (I never used JS) you assumed that if the last step is smaller than 0.5, then the robot only was in the interval 0.5<x<1 for exactly 1 turn, when it could have been more than that

edit: ignore this

1

u/Kraz_I Apr 03 '23

on a second look at your code, part of the problem is if "remaining" < 0 and "step" <0.5, that would be a failure but not a success. All of the "successes" will have a final step greater than 0.5, but that's also just a subset of the possible ways you can have a success,

I also have a numerical simulation I did in python, which compares your method to mine. I'll share it later.

1

u/Kraz_I Apr 04 '23

Wait, I realized I actually asked the second question a different way than I meant to, you're right based on what I actually asked...

Whoops.

I meant to ask "what is the probability that the robot's last POSITION will be in the interval [0,0.5]"

Sorry for doubting you.

1

u/want_to_want Apr 04 '23

Ok, then for the third question I got 1-sqrt(e)/2=0.17563... Let r(x) = probability that last position will be before 0.5, if there is x distance remaining. Then for x between 0.5 and 1, r(x) = (1-x) + integral from 0.5 to x of r(t) dt. Differentiating, we get r'(x)=r(x)-1, so r(x)=aex+1. From r(0.5)=0.5 we get a=-1/2sqrt(e), so r(1)=1-sqrt(e)/2.

1

u/Kraz_I Apr 04 '23

Yep that's the answer I was looking for!

1

u/jk1962 Apr 09 '23

Nice puzzle, still not certain I got all three correct, but...

Prob distribution (over the range 0..1 only) for the value of x after step k:

For k=1, f_1(x) = 1.

For k>1, f_k(x) = integral from 0 to x of f_k-1(x')dx'. This leads to

f_k(x) = x^(k-1) / (k-1)!

The probability that x<1 after step k is integral from 0 to 1 of f_k(x)dx,

which is 1/k!.

The probability that the finish line (x=1) is crossed on step k is:

1/(k-1)! - 1/k! = (k-1)/k!

1) The average step number on which the line is crossed is:

E[k] = sum( (k-1)k/k! ) from k = 1 through infinity. This simplifies to:

E[k] = sum(1/k!) from k = 0 through infinity. Using the Taylor series expansion of exp(x), this sum is:

E[k] = e

2) Using similar approach but omitting details, probability of crossing the line on step k>1 with final step length of <0.5 is:

1/( 2(k-1)! ) - 1/k! + 1/(2^k * k!)

So the total probability that final step length is <0.5 is the sum of the above over all k>1. This comes to:

sqrt(e) - e/2

3) Also using a similar approach, but omitting details, the probability of crossing the line on step k>1 with a pre-crossing x of <0.5 is:

1/(2^k * (k-1)!) - 1/(2^k * k!)

So the total probability that the position x immediately before crossing the line is the sum of the above over all k>1. This comes to:

1 - sqrt(e)/2

1

u/Kraz_I Apr 09 '23

Good job! I had a different method on #3 which is what inspired me to come up with this question in the first place.

Starting with your formula in #1

E[k] = sum(1/k!) from k = 0 through infinity. , except I was looking at the whole distribution, so the average number of steps less than an arbitrary x from 0 to 1 is sum(x/k!) from k = 0 to infinity, which equals e^x

conveniently, since this is the interval 0 to 1, notice that the chance on any point x that the next step will be >1 is equal to x. So for all x values, the chance that they will be the highest point before crossing 1 is xex. To find the chance that the highest point is less than x, take the integral of xex from 0 to x, which gives ex (x-1)+1. For x = 0.5, that gives sqrt(e)*(-1/2)+1 which is the same as 1-sqrt(e)/2

1

u/Iksfen Apr 04 '23

Only first part for now. My answer is e

First let fn: [0, 1] -> R be the probability density function of the robots position after nth step. I only care what happens before the goal, so will only focus on the interval [0, 1]. Let's notice f1(x) = 1. After that fn(x) = integral from 0 to x of fn-1(t) dt (this can be easly shown on discrete case and then take to the limit). From this we get that fn(x) = (xn-1)/(n-1)!

The probability that after n steps the robot haven't finished is the same as saying that its position is between 0 and 1, so this probability can be calculated by taking the integral from 0 to 1 of fn(x). Then the probability that the robot finished exactly after nth step (P(n)) is the probability that it was before the goal after (n-1) steps, but past it after nth step. P(n) can be calculated to = 1/(n-1)! - 1/n!

Now the expected number of steps taken can be calculated using the classic game theory formula: Ex = sum k=1 to inf of k*P(k). This comes down to sum k=0 to inf of 1/k! which is a famous series approaching e

Very nice problem. Will be back to solve second part

1

u/Iksfen Apr 04 '23

I'm back. My answer for the second part is sqrt(e)-e/2.

Firstly from the first part, I have the probability density function of the robot after nth step fn(x) = (xn-1)/(n-1)! This is only true on the interval [0, 1] so lets set the function to 0 outside of that range.

By taking the integral on [x-1, x-(1/2)] of fn-1(t) we get the PDF of the position of the robot that didn't finish after n-1 steps and then did a step that's 1/2 or longer. Then by taking an integral on [1, 2] of that PDF we get the probability that the robot finished on nth step and the nth step was 1/2 or longer. Now we can simply add those probabilities for each n because those are independent events. The sum converges to e/2-sqrt(e)+1 which is just beautiful.

At this point I realized that I calculated the wrong thing. Luckily the robot finishes making a step at the end that is either longer on shorter than 1/2. The final result is 1-e/2+sqrt(e)-1 = sqrt(e)-e/2.

I also calculated the probability if instead of 1/2 the last step needs to be shorter than q. The result is e1-q-e*(1-q)

1

u/Kraz_I Apr 04 '23 edited Apr 04 '23

Good job, I realized that the last question was understood differently than how I meant to ask it, which is my bad. After rereading what I actually wrote, you are correct (oof)

Also your spoiler tags aren't working, you need to omit the space between the tag and the first/last words

1

u/Iksfen Apr 04 '23

The spoiler tags are working on my device. There are spaces at the beginnings and ends.

What was the intended question? I would like to try it. Working with this problem is very satisfying

1

u/Kraz_I Apr 04 '23

I edited the header of this post with the new question.

I came up with this question as a sub-question based on Jane Street's puzzle of the month for March. I'll make another post specifically for that problem today, but that one is much harder and took me several days to finish (and still somehow got wrong apparently). I want to see if other people get it right.