Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Coin toss with rule +1 if it is a head and -1 otherwise

  1. Sep 25, 2007 #1
    Coin toss with rule "+1 if it is a head and -1 otherwise"

    25 < my age < 54. Start from the number of my age and toss a fair coin, plus one if it is a head and minus one otherwise, on average, you need to toss 210 times to hit the bound, i.e. 25 or 54. There are two integers satisfying the condition. Fortunately, the smaller one is my age.
  2. jcsd
  3. Sep 25, 2007 #2
    if what you say is true you could subtract 24 from 25, 54 and your age to get the same problem so 1<age-24<30. 30 *7 = 210. 7 = 2^3-1. 30 = 2^5-2 = 2*(2^4-1) I am not sure what these numbers mean but powers of 2 would seem important in coin toss problems. I searched "coin toss" in Sloane's Online Encyclopedia of Integer Sequences and got ten sequences of interest but no hint of solution. It is interesting that although the average ratio of heads to tails should be 50:50 that there would be an average for the number of tosses to get a certain offset value.
  4. Sep 26, 2007 #3
    First, is this a trick question? I spent some time on this, and wanted to try to practice my programming skills to figure it out. I have programmed a model of this question. I am having trouble interpretting the results though. I create an array (call it array A) of size 210. I fill it with random 1's and -1's. I sum this array and record the result in a seperate array (call it array B).

    Now I looped this so I would record 10,000 results in array B. The problem is the results are all Positive, and negative, and the average is very close to zero.

    We want to find out, on average, after 210 flips, how much would we add, or subtract from the age. So it seems clear that I need to seperate the positives and negatives into two seperate arrays, and average those. But what do I do with all the zeros?

    Should I count them, and put that many zeroes on the positive, and the same amount in the negatives? Do I put half of them in the positives and half in the negatives?

    I need to do something with them because it affects the number that I will be dividing by.
  5. Sep 26, 2007 #4
    By the way, I ask if this is a trick question because of the wording. "plus one if it is a head and minus one otherwise"

    Why does it not specifically state, minus one if it is a tails. Otherwise? If it lands on it's edge do I subtract 1? If a lion eats the coin in mid air do I subtract 1?
  6. Sep 26, 2007 #5
    You probable should be looking not at the low values or the extreme values, those farthest away from 0 are probably more likely to first appear with more coin tosses while those near 0 are more likly to first appear with fewer coin tosses. I dont think it is a trick question, see for instance http://www.research.att.com/~njas/sequences/A050231 [Broken] also see A050232, A050033, A033504 and A059943 in the same site and see http://mathworld.wolfram.com/CoinTossing.html. There should be an answer but it cant be by just looking at results for 210 tosses of the coin since you want to find the value that is first reached on an average of 210 tosses and to know that you have to consider what happens after of n tosses where n is other than 210. I thought it might be a trick question too (like what is the average of "n" and infinity) but after looking at the sites above I changed my mind.
    Last edited by a moderator: May 3, 2017
  7. Sep 26, 2007 #6
    The guess I made was he was refering to the [tex]STD = \sqrt{pq*210}=7.25 ...[/tex] So that at this point 68% of the time the variation would not move more than 7 whole points. So if the age was 32 (the starting point) it may reach or pass the boundry of 25. ???
    Last edited: Sep 26, 2007
  8. Sep 27, 2007 #7
    So I have modified my program. It will now start at with the value 26. It will create the arrays 10,000 times and average how many flips it took to get to the boundry (either 25, or 54). Once I have an average for 26, it will move on to 27 and so on and so forth until it reaches 53. I will then look at the average number of flips it took for each integer contained in (25, 54).

    This should work, right?
  9. Sep 27, 2007 #8
    By the way, this process, is almost crashing my computer because of the amount of calculation being done. I expect this to run over night. at the very least. I will update when I have results.
  10. Sep 27, 2007 #9
    I have finished running the program. I am positive that I have done this correctly.

    Just to recap, here is what I did.

    I had the user input a number between 25 and 54. Then I basically flipped a coin and followed the rules stated, until I hit the bounds. I did this 10,000 times for each number between 25 and 54. Then I averaged those 10k numbers. This gave me the average number of coin flips it takes to reach the bounds for each age in between 25 and 54.

    For 26, it takes on average 27 flips.
    For 27, it takes on average 52 flips.
    For 28, it takes on average 76 flips.
    For 29, it takes on average 98 flips.
    For 30, it takes on average 115 flips.
    For 31, it takes on average 132 flips.
    For 32, it takes on average 150 flips.
    For 33, it takes on average 167 flips.
    For 34, it takes on average 173 flips.
    For 35, it takes on average 188 flips.
    For 36, it takes on average 188 flips.
    For 37, it takes on average 196 flips.
    For 38, it takes on average 205 flips.
    For 39, it takes on average 210 flips.
    For 40, it takes on average 210 flips.
    For 41, it takes on average 205 flips.
    For 42, it takes on average 196 flips.

    At this point it becomes symmetric.

    So there are two options where it averages 210 flips. When the person is either 39 or 40. Since the problem states that he is the lesser age. The person must be 39.

    I think coding a program to simulate this experiment was pretty cool, but I would love to see the solution worked out with formulas.
  11. Sep 28, 2007 #10

    matt grime

    User Avatar
    Science Advisor
    Homework Helper

    Let E(n) be the expected time to hit the boundary starting at n. This satisfies the recurrence relation

    E(n)=1+ (E(n-1)+E(n+1))/2

    Solve, subject to the conditions E(25)=0 and E(54)=0
  12. Sep 29, 2007 #11
    But there are some discrepancies with the Diffy's data e.g. by as much as 10 or more
    Last edited: Sep 29, 2007
  13. Sep 29, 2007 #12


    User Avatar
    Homework Helper

    I would've thought the problem could be viewed as a simple 1-d unbiased random walk where the expected endpoint is given and the origin is to be determined.

    The (arithmetic mean) average distance from the origin <d> after N steps is, to a very good approximation for large N, [tex]\sqrt{\frac{2N}{\pi}}[/tex], which gives around 11.56.

    The rms distance <d^2>^0.5 is [tex]\sqrt{N}[/tex] giving 14.49.

    The first measure gives possible values of (25+11.56 = 36.56) or (54-11.56 =42.44). Naturally, these values are asymmetric in the sense that each is "closer" to one bound than the other, meaning they would (approximately) satisfy the 210-step condition only with one bound. Since the smaller value is wanted, that would be 36.56 (36 or 37 if integers are required, and 36 is the smaller value).

    The second measure gives a nearer to symmetric value (25 + 14.49 = 39.49, which is close to 54 - 14.49 = 39.51) In this case, the single value 39.5 (39 or 40 if integers req'd, 39 is the smaller value) would be the answer.
    Last edited: Sep 29, 2007
  14. Sep 29, 2007 #13

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    What you did was a Monte Carlo experiment. More below.
    The basis for the answer is in the Matt Grime's post, which follows right after yours. Matt Grimes showed a way to solve the problem. Remember that Matt is a mathematician. Showing that a solution exists suffices. You've heard the joke about the physicist, the engineer, and the mathematician, haven't you?

    This leads to the tridiagonal matrix equation

    1 & 0 & 0 & 0 & \cdots & & & \\
    -1/2 & 1 & -1/2 & 0 & \cdots & & & \\
    0 & -1/2 & 1 & -1/2 & \cdots & & & \\
    \vdots & & & & \ddots & & & \\
    0 & \cdots & & & & -1/2 & 1 & -1/2 \\
    0 & \cdots & & & & 0 & 0 & 1
    \end{matrix}\right] \boldsymbol x =
    0 \\
    1 \\
    1 \\
    \vdots \\
    1 \\

    A comparison of the exact results against the Monte Carlo experiment:

    \text{N} & \text{Exact} & \text{Monte} \\
    26 & 28 & 27 \\
    27 & 54 & 52 \\
    28 & 78 & 76 \\
    29 & 100 & 98 \\
    30 & 120 & 115 \\
    31 & 138 & 132 \\
    32 & 154 & 150 \\
    33 & 168 & 167 \\
    34 & 180 & 173 \\
    35 & 190 & 188 \\
    36 & 198 & 188 \\
    37 & 204 & 196 \\
    38 & 208 & 205 \\
    39 & 210 & 210\end{matrix}[/tex]

    You cannot expect Monte Carlo techniques to yield exact answers. The accuracy of the results depends on the number of trials and the nature of the underlying distribution. In this case, the Monte Carlo experiment appears to have a negative bias and is not accurate enough to distinguish between 37, 38, or 39. But it is close.
    Last edited: Sep 29, 2007
  15. Sep 30, 2007 #14
    I checked my hunch the average number of times to reach a bondary exactly must be of the form such that if there are zeros where the bondary is reached then the case must be of the form where there exists P(n) = P(n+1) = 2^x-2 or P(n) = P(n+2) for some n. I thought I proved that if the first case is present of the first case then P(n) must be either of the form P(n) = (2^(x-1)-1)*(2^(x + 1)-2) and the zeros are at P(n - 2^x + 1) or P(n+2^x-1)); or P(n) = x(x+1) in which the zeros are at P(n-x) or P(n+x+1). This seem to conflict with the statement the the Matt's post shows the existance of a solution for all cases in which there is are zeros at P(z) and P(z+2n+1). For instance the existance of bondary points at 1 and 18 appeared impossible but then I realized that I merely proved that P(n) = P(n+1) = 18 is impossible and the last possiblity in fact proves the existance of a solution.
  16. Sep 30, 2007 #15

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Matt's solution, follows directly from the problem statement. Define E(n) as the expected value of reaching a boundary point from some initial value n. The expected value for the two boundary points is obviously zero. For an interior point, at least one flip is needed, and this flip moves the initial point to the points n-1 or n+1 with equal probability. Hence E(n) = 1 + (E(n-1)+E(n+1))/2 for the interior points.
  17. Sep 30, 2007 #16
    I agree that Matts solution is correct but that doesn't provide an immediate solution except by solving equations in matrix form. Matts solution provides an recursive formula [tex]P_{n} = 2P_{n-1} - P_{n-2} -2[/tex] so if we know the initial two values we can compute the remaining values recursively. If A and B are the boundary points with B > A then P(A) = 0 and P(A+1) = B-A-1 so it is easy to obtain the result recursively. Also, if C = Foor((A+B)/2) then P(C) equals (C-A)^2 if A+B is even and equals (C-A)^2+C-A if A+B is odd.
    Last edited: Sep 30, 2007
  18. Sep 30, 2007 #17

    matt grime

    User Avatar
    Science Advisor
    Homework Helper

    I don't immediately see the second equality there. What is the reason for that?
  19. Sep 30, 2007 #18
    It follows from induction. If A+B is odd then P((A+B-1)/2) = P((A+B+1)/2)=X
    P((A+B+1)/2) = X
    P((A+B+3)/2) = X-2
    P((A+B+5)/2) = X-2*2 -2 = X-6
    P((A+B+7)/2) =X-6*2 + 2 -2 = X-12
    P((A+B+9)/2) =X-12*2+6-2 = X-20
    P((A+B +B-A-2)/2) = P(B-1) = X - (B-A-1)*(B -A -3)/4
    P((A+B +B-A)/2) = P(B) = X - (B-A-1)*(B-A+1)/4

    P(B-1)-P(B) = (B-A-1)(3+1)/4 = B-A-1

    A similar proof for A+B is even also leads to the same result.
    Last edited: Sep 30, 2007
  20. Sep 30, 2007 #19

    matt grime

    User Avatar
    Science Advisor
    Homework Helper

    Nope, I fail to see why the expected hitting time from (A+B+3)/2 is the expected hitting time from (A+B+1)/2 minus 2.

    The first thing you wrote was jus symmetry about the mid point. Why does moving one step away from the mid point decrease your expected hitting time by 2?
    Last edited: Sep 30, 2007
  21. Sep 30, 2007 #20
    Under my assumption A+B is odd, therefore B-(A+B+1)/2 = (A+B-1)/2 -A and B-(A+B-1)/2 = (A+B+1)/2 - A so the distances from the boundary points is equal and E((A+B-1)) = E((A+B+1)/2) = X
    But E((A+B+1) -(E((A+B-1)/2 + E((A+B+3)/2)/2 = 1
    So E((A+B+3)/2) = 2(E((A+B+1)/2)-E((A+B-1)/2 -2 = 2X-X -2 = X-2
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook