Subscribe via feed.

Strange Die

Posted by ragknot on October 3, 2011 – 2:45 am

Just like Chris’s #4 (previous post) but …
you have a strange die. Half the time you roll a six, it apprears as a seven. What is the average number of rolls of a die to have got each number (1 to 7) at least once?Знакомства


This post is under “Tom” and has 14 respond so far.
If you enjoy this article, make sure you subscribe to my RSS Feed.

14 Responds so far- Add one»

  1. 1. Your name Said:

    infinity
    as you’ll never get a 6

  2. 2. Chris Said:

    Hi ragknot. Good problem, thanks. I’ll have a bash later (8+ hours from now). I won’t be using a program (except maybe to verify).

    Hi Your name. I’m pretty sure that ragknot means that you are equally likely to get a 6 or a 7.

  3. 3. ragknot Said:

    I tried to pass this on. The die has only six sides, so 1/6th of the rolls should be a one. This will make the problem similiar to others. But the deal is this.. one time out of six the “strange” side will be up… and 1/2 of the time it will be a six, the other half, it will be a seven.
    It is NOT like a seven sided die. Funny huh?

  4. 4. Jan Said:

    yeah but you probably should have calculated the answer by hand first. if you did that you would not have posted the problem. i am half way and my sub answer is 125661/6930, the expected time it takes to roll all if you have already rolled a 6.
    i bet you used a computer program.

  5. 5. Jan Said:

    prob 99% chance that i made a mistake somewhere, but my guess is 49817/2310=21.5658.

  6. 6. Chris Said:

    Hi Jan. Ragknot almost always uses a computer program, he is not mathematically minded, but he does like practical engineering solutions to problems. You have the correct answer. Unlike you, I resorted to decimals rather than exact numbers.

    I’m quite shocked at how difficult the problem became with such a seemingly small change from a normal die.

    —-

    Call faces 1,2,3,4 and 5 type 1 and faces 6 and 7 type 2. The probability of throwing a particular type 1 face is 1/6 and a type 2 face is 1/12. The probability of rolling any one of x type 1 faces is x/6 and of rolling any one of y type 2 faces is y/12.

    NB I’m using [] rather than () for function brackets. Define n[x,y] as the average number of rolls required to see all x type 1 faces and all y type 2 faces. We want n[5,2]. While there are unseen faces, we must make a roll. If we roll a previously unseen type x or y face, then x or y is reduced by 1 and we have n[x-1,y] or n[x,y-1] rolls to do. If we roll a previously seen face, then we still have n[x,y] rolls to do, and the probability of that is (1 – x/6 – y/12).

    Altogether that =>
    n[x,y] = 1 +n[x-1,y] x/6 +n[x,y-1] y/12 +n[x,y] (1 – x/6 – y/12)

    Solving for n[x,y] =>
    n[x,y] = (12 + 2x n[x-1,y] +y n[x,y-1])/(2x + y) {E1}

    {E1} fails if x = y = 0. However, it is clear that n[0,0] = 0

    Let y = 0. Then {E1} becomes
    n[x,0] = (12 + 2x n[x-1,0]) / 2x = 6/x + n[x-1,0]
    Letting x = 1,2,3,… =>
    n[1,0] = 6/1 + n[0,0] = 6 + 0 = 6 (as expected)
    n[2,0] = 6/2 + n[1,0] = 3 + 6 = 9
    n[3,0] = 6/3 + n[2,0] = 2 + 9 = 11
    n[4,0] = 6/4 + n[3,0] = 1.5 + 11 = 12.5
    n[5,0] = 6/5 + n[4,0] = 1.2 + 12.5 = 13.7
    and for fun
    n[6,0] = 6/6 + n[5,0] = 1 + 13.7 = 14.7 (which should look familiar).

    Let y = 1. Then {E1} becomes
    n[x,1] = (12 + 2x n[x-1,1] + n[x,0]) / (2x + 1)
    Letting x = 0,1,2,3,… =>
    n[0,1] = (12 + 0 + 0) / 1 = 12 (as expected)
    n[1,1] = (12 +2 n[0,1] +n[1,0])/3 = (12 +2*12 + 6)/3 = 14
    n[2,1] = (12 +4 n[1,1] +n[2,0])/5 = (12 +4*14 + 9)/5 = 15.4
    n[3,1] = (12 +6 n[2,1] +n[3,0])/7 = (12 +6*15.4 +11)/7 = 16.48…
    n[4,1] = (12 +8 n[3,1] +n[4,0])/9 = (12 +8*16.48… +12.5)/9 =17.37…
    n[5,1] = (12 +10 n[4,1] +n[5,0])/11 = (12 +10*17.37…+13.7)/11 =18.13…

    Let y = 2. The {E1} becomes (after removing the common factor of 2)
    n[x,2] = (6 + x n[x-1,2] +n[x,1]) / (x+1)
    Letting x = 0,1,2,3,… =>
    n[0,2] = (6 + 0 + n[0,1]) / 1 = (6 +12) = 18
    n[1,2] = (6 + n[0,2] + n[1,1])/2 = (6 + 18 +14)/2 = 19
    n[2,2] = (6 + 2n[1,2] +n[2,1])/3 = (6 +2*19 +15.4)/3 = 19.8
    n[3,2] = (6 + 3n[2,2] +n[3,1])/4 = (6 +3*19.8 +16.48…)/4 = 20.47…
    n[4,2] = (6 + 4n[3,2] +n[4,1])/5 = (6 +4*20.471… +17.38…)/5 = 21.05…
    n[5,2] = (6 + 5n[4,2] +n[5,1])/6 = (6 +5*21.052… +18.13…)/6 = 21.56…

    High precision … values are
    16.485714285714285714285714285714
    17.37619047619047619047619047619
    18.1329004329004329004329004329
    20.471428571428571428571428571429
    21.052380952380952380952380952381
    21.565800865800865800865800865801
    The last being the value required by ragknot

    Although I did it the hard way (using Windows calculator), the recursion lends itself to coding very well indeed, as shown by the following quick and dirty:

    Sub Strange()
       Dim x As Integer
       Dim y As Integer
       Dim n(-1 To 5, -1 To 2) As Double

       n(0, 0) = 0#
       For y = 0 To 2
          For x = 0 To 5
             If x+y<>0 Then n(x, y) = (12+2*x*n(x-1,y)+y*n(x,y-1))/(2*x+y)
          Next x
      Next y
      Debug.Print n(5, 2)
    End Sub

  7. 7. ragknot Said:

    Wow Chris, that is a lot of programming.
    Tell me if this is right.

    1/6 of the rolls should be a one
    1/6 of the rolls should be a two
    1/6 of the rolls should be a three
    1/6 of the rolls should be a four
    1/6 of the rolls should be a five
    1/12 of the rolls should be a six
    1/12 of the rolls should be a seven

    Doesn’t this make it easy?

  8. 8. Chris Said:

    Hi ragknot. I used that information. I only tacked on a tiny bit of code at the end of my comment, and I only did that after calculating the answer by hand.

  9. 9. ragknot Said:

    Chris, I am going to review your code, but this was my code.
    And “Yes” both your answer and Jan’s are good.

    Sub test5()
    Randomize
    Dim b, t, r As Long
    Dim got(7) As Integer
    Dim i As Long
    Do
    i = i + 1
    r = Int(Rnd() * 6 + 1)
    If r = 6 Then
    If Rnd() > 0.5 Then r = 7
    End If
    got(r) = 1
    t = 0
    For r = 1 To 7
    t = t + got(r)
    Next r
    If t = 7 Then
    b = b + 1
    For r = 1 To 7
    got(r) = 0
    Next r
    If i > 1000000 Then Debug.Print i / b: Exit Do
    End If
    Loop
    End Sub

  10. 10. ragknot Said:

    that was smart, and complex code Chris.

  11. 11. Chris Said:

    Hi ragknot. The bulk of my post wasn’t [computer] code, it was mathematics.

    Your code and mine do completely different things. Yours is a Monte Carlo simulation, mine is simply calculating the recursion relation
    n[x,y] = (12 + 2x n[x-1,y] +y n[x,y-1])/(2x + y). It is not an iterative approximation to the result. I had really solved the problem when I derived the recursion equation {E1} about one quarter of the way into my post.

    If I had written the tiny bit of code that I posted in Mathematica, it would have given me the exact result 125661/6930 that Jan found.

    I’ll check the Lambert W page to see what you mean. However, I only use Internet Explorer.

  12. 12. ragknot Said:

    When I read your code, I found it was not what I expected. I was at work, and glanced a then long comment and thought it was vba code. When I got home and actually read it. I would have to spend more time to understand how you were doing it. I did run the short VBA where it ended, but did not understand it either, BUT I saw it did work, and had the right results.

    My method it just to roll the dice and evaluate the results. In about 10 seconds I can see about one million results and assume it is right maybe to a couple of decimal places. I try it a couple of more times and see how close the results were.

    Also I should not mentioned something else. I think I was wrong. I am going to remove it.

  13. 13. Chris Said:

    Hi ragknot. I finally realised that you hadn’t studied my post.

    I guess you sorted out the Lambert W stuff.

    The “exact” calculation is done in the blink of an eye. Now I’ve used more sensible variables etc (see Strange die 2), I realise that I should have been able to generate the recursion equation and write the code in 15 minutes or less.

  14. 14. Chris Said:

    NB. There is little or no hope of making a useful closed form of the function n[x,y]. Even the simplest case of a regular die requires the harmonic series “function”, which although “closed”, isn’t a proper function i.e. it is a sum where the number of terms is dependendent on the data.

    For the simple die, n[6] = 6 H[6], where H[n] = Sum[k = 1 to n, 1/k]

Post a reply




PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\ext\php_mssql.dll' - The specified module could not be found. in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\ext\php_pdo_mssql.dll' - The specified module could not be found. in Unknown on line 0