Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dice problem
#31
Quote:That formula can't be right...

Opps, typo. The actual formula looks like this:
Code:
nCk =     n!
      ----------
      k!(n - k)!

You can read all about permutations and combinations here.
esus saves.... Passes to Moses, shoots, he scores!
Reply
#32
Quote:Now, I mean a bell curve? Pass grade 10 Algebra and you will understand ;P

Riiiiigghttttt. Genius boi?

It was never taught to me. Now before bragging about intelligence here, can you point a link about a bell curve to me? It may be called a different name in this parts of the world. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#33
Maybe "Gauss curve" sounds more familiar to you, Rel.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#34
Thank you very much for the info. Unlike our friend who assumes that because its called that way in his country, it's called that way everywhere else. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#35
Quote:Now before bragging about intelligence here, can you point a link about a bell curve to me?

What the hell are you talking about? I never said anything about intelligence, I was talking about education.

Quote:It may be called a different name in this parts of the world. :*)

True enough. But, I was taught that it's called a bell curve. It's also known as a normal curve or in statistics, a normal distrobution. I've never heard it refered to as a 'gauss curve', but after reading a bit on it, it's the same thing.

Quote:To illustrate I'll use a situation with 4 dice where we want exactly 2 of the dice to be fours

You'll notice, that the original question didn't say, 'exactly 5 of 8 sides equalling 4', it said, '5 sides of 4 on eight 6 sided dice.' So, 6 sides of 4 would be two instances of 5 sides of 4.
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Reply
#36
Quote:You'll notice, that the original question didn't say, 'exactly 5 of 8 sides equalling 4', it said, '5 sides of 4 on eight 6 sided dice.' So, 6 sides of 4 would be two instances of 5 sides of 4.

Ugh, I did four fours, instead of five fours anyway. Stupid numbers ;-). I interpretted the question as being exactly five fours using eight dice, because the question doesn't specify otherwise.
esus saves.... Passes to Moses, shoots, he scores!
Reply
#37
That's why I was asking you if it was the same as "Skewness". Skewness is technically a *curve*.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#38
Yeah, the fact that it didn't state 'exactly' is why I went with the 'multiple sub-sets in the set' method.

As to skewness, I've never heard it refered to as a curve, rather as a linear progressive offset.
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Reply
#39
The problem asks for the number of times you get 5 fours on a roll of 8 dice. As TBBQ said this is different from the number of times you get atleast 5 fours. It means exactly 5 fours.

Since each of the 1000 rolls is independent, as Rel wrote at the beginning, the expected number is the number of rolls times the probability for one roll. The probability of getting r fours on n dice has a binomial distribution:
Code:
n = 8          ' The number of dice
r = 5          ' The number of fours
p = 1 / 6      ' The probability of rolling a four on one die
nCr = 56       ' This is n choose r.   Loose told us this is n! / (r! * (n - r)!)
               ' And TBBQ had calculated it earlier

Pof5_4s = nCr * p^r * (1 - p)^(n - r)
The result is a probability of 0.0041676

1000 * 0.0041676 = 4.17
This is the same number that Aga posted (though he rounded it to 4) and close to the experimental values that TBBQ got.

This program compares the results of a probability experiment with the expected values. It runs a number of trials of 1000 rolls, and uses a bar chart to display the results. Cyan lines on the graph indicate calculated values.

If you run the program, you will see that some trials will have have results that are way off the calculated mean, but the average of them is usually very close to it. You will also see that even those results are predicted fairly well.

If you change the number of fours, the program will automatically change the graph window and scale. It will always get you close to where you want to be, but doesn't work perfectly. You can set AutoFit = 0 and put in your own settings to correct.

Another of my simple programs that got out of control

You might want to look at my Choose function. It is more efficient than following the formula literally, and will handle larger numbers because it doesn't multiply everything out.

Code:
DECLARE SUB ScreenSetup (BShft%, HSpc%, Shift%, Range%, Zero%)
DECLARE SUB DataBox (p!, Rolls AS INTEGER)
DECLARE SUB PlotExpectedVals (BShft%, HSpc%, Max%, Min%, n%, p AS SINGLE, Trials%, Zero%)
DECLARE FUNCTION Choose# (n%, r0%)
DEFINT A-Z
DIM Results(500) AS INTEGER

DIM p AS SINGLE
DIM Total AS LONG
DIM Mean AS SINGLE, Median AS SINGLE, Mode AS INTEGER
DIM TotDev AS SINGLE, SDev AS SINGLE

'--------------------- Experiment Parameters ----------------------
Dice = 8               ' number of dice rolled at a time          '
Faces = 6              ' number of sides on a die                 '
Num4s = 5              ' desired number of 4's per roll           '
Rolls = 1000           ' number of rolls of dice per trial        '
Trials = 1000          ' total number of trials                   '
'------------------------------------------------------------------'
'------------- Change to fit the graph on the screen --------------
AutoFit = -1            ' fit graph on screen based on calculations
HSpc = 4               ' text spaces per bar on the graph (1-5)   '
Shift = 0              ' minimum value on the graph (0-240)       '
'------------------------------------------------------------------'
p = Choose(Dice, Num4s) * (Faces - 1) ^ (Dice - Num4s) / Faces ^ Dice

Mean = Rolls * p
Median = INT(Mean + .5)
Mode = Median
SDev = SQR(Mean * (1 - p))

IF AutoFit THEN
  HSpc = 76 / (7 * SDev)
  IF HSpc < 1 THEN HSpc = 1
  IF HSpc > 8 THEN HSpc = 8

  Shift = Mean - 3.5 * SDev
  IF Shift < 0 THEN Shift = 0
END IF

Range = 76 \ HSpc - 1
BShft = 32 - 4 * ((HSpc + 1) MOD 2) + 8 * ((76 - HSpc * (Range + 1)) \ 2)
Zero = 444

ScreenSetup BShft, HSpc, Shift, Range, Zero
DataBox p, Rolls
PlotExpectedVals BShft, HSpc, Range + Shift, Shift, Rolls, p, Trials, Zero

RANDOMIZE TIMER
MinResult = Rolls
MaxResult = 0

FOR Trial = 1 TO Trials  '-------- Probability Experiment-----------
  Count = 0                                                          
  FOR roll = 1 TO Rolls                                          
    Fours = 0
    FOR Die = 1 TO Dice
      Face = RND * Faces + .50000001#
      Fours = Fours - (Face = 4)
    NEXT
    Count = Count - (Fours = Num4s)
  NEXT

  IF Count < MinResult THEN MinResult = Count
  IF Count > MaxResult THEN MaxResult = Count
  Results(Count) = Results(Count) + 1
  Total = Total + Count

  IF Count >= Shift AND Count <= Shift + Range THEN
    x0 = 8 * HSpc * (Count - Shift) + BShft
    LINE (x0, Zero - Results(Count))-STEP(8 * HSpc - 2, 0), 14
  END IF
  IF INKEY$ = CHR$(27) THEN GOTO EndProgram
NEXT  '------------- End of Probability Experiment------------------

PlotExpectedVals BShft, HSpc, Range + Shift, Shift, Rolls, p, Trials, Zero

Mean = Total / Trials
Mode = 0
ModeAmount = 0
Median = -1
n = 0

FOR i = MinResult TO MaxResult
  IF Results(i) > ModeAmt THEN
    Mode = i
    ModeAmt = Results(i)
  END IF
  n = n + Results(i)
  IF Median = -1 THEN
    IF n = Trials / 2 THEN
      Median = i + .5
    ELSEIF n > Trials / 2 THEN
      Median = i
    END IF
  END IF
  TotDev = TotDev + Results(i) * (i - Mean) ^ 2
NEXT
SDev = SQR(TotDev / (Trials - 1))

LOCATE 4, 73: PRINT USING "###.###"; Mean
LOCATE 6, 73: PRINT USING "###.#  "; Median
LOCATE 8, 73: PRINT USING "###    "; Mode
LOCATE 10, 73: PRINT USING "###.###"; SDev

EndProgram:
COLOR 8

DEFDBL A-Z
FUNCTION Choose (n%, r0%)
  IF r% > n% THEN
    PRINT "ERROR: n must be greater than or equal to r"
    STOP
  END IF
  IF n% - r0% > r0% THEN
    r% = n% - r0%
  ELSE
    r% = r0%
  END IF
  C = 1
  FOR i% = 1 TO n% - r%
    C = C * (n% + 1 - i%)
    C = C / i%
  NEXT
  Choose = C
END FUNCTION

DEFSNG A-Z
SUB DataBox (p, Rolls AS INTEGER)
  Mean = Rolls * p
  LINE (442, 0)-STEP(200, 88), 0, BF
  LOCATE 2, 64: PRINT "EXPECTED  ACTUAL"
  LOCATE 4, 57: PRINT "MEAN   ";
                PRINT USING "###.###"; Mean
  LOCATE 6, 57: PRINT "MEDIAN ";
                PRINT USING "###.#"; INT(Mean + .5)
  LOCATE 8, 57: PRINT "MODE   ";
                PRINT USING "###"; INT(Mean + .5)
  LOCATE 10, 57: PRINT "ST.DEV.";
                PRINT USING "###.###"; SQR(Mean * (1 - p))
END SUB

DEFINT A-Z
SUB PlotExpectedVals (BShft, HSpc, Max, Min, n, p AS SINGLE, Trials, Zero)
' This sub plots the expected number of trials in which the right number
' of dice have a face value of 4 exactly r times, for each r.
' The expected value has a binomial distribution given by
'       E = (nCr * p^r * (1-p)^(n-r)) * Trials
' where nCr (read n Choose r) = n! /(r! * (n-r)!)  Handled by Choose(n, r)
'       n is the number of times dice are rolled in a trial
'       r is the number of times the right number of fours occur
'       p is the probability of getting the right number of fours in a roll
'       Trials is the total number of trials to be run

  FOR r = Min TO Max
    Expected = Trials * Choose(n, r) * p ^ r * (1 - p) ^ (n - r)
    x = HSpc * (8 * (r - Min) + 2) + BShft
    IF Expected <> 0 THEN
      LINE (x, Zero - Expected)-STEP(HSpc * 4 - 2, 0), 3
    END IF
  NEXT
END SUB

SUB ScreenSetup (BShft, HSpc, Shift, Range, Zero)
  SCREEN 12
  WIDTH 80, 60

  LINE (26, Zero + 1)-(636, 0), 1, BF                 'Graph box

'-=-=-=-=-=-=-=-=-=-=-=-=- Make Grid -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  FOR i = 0 TO 440 STEP 20
    IF (i MOD 200) = 0 THEN '------ Write Vertical Labels -------
      LOCATE 56 - 25 * (i \ 200), 1                              '
      PRINT USING "###"; i;                                      '
    END IF    '--------------------------------------------------
    '------------------ Vertical Scale --------------------------
    LINE (25, Zero - i)-STEP(611, 0), 8 + (i MOD 100 = 0)
  NEXT
                                                                    
  Clmn0 = (85 - HSpc * Range) \ 2
  FOR i = 0 + Shift TO Range + Shift '--- Horizontal Labels ---
    IF ((i + 1) MOD 2) OR (HSpc > 1) THEN                        '
                                                                 '
      IF i > 99 THEN ' Print Hundreds - - - - - - - - - - - - -  '
        LOCATE 57, HSpc * (i - Shift) + Clmn0                  ' '
        PRINT USING "#"; i \ 100;                              ' '
      END IF   '- - - - - - - - - - - - - - - - - - - - - - - -' '
                                                                 '
      IF i > 9 THEN  ' Print Tens - - - - - - - - - - - - - - -  '
        LOCATE 58, HSpc * (i - Shift) + Clmn0                  ' '
        PRINT USING "#"; (i MOD 100) \ 10;                     ' '
      END IF   '- - - - - - - - - - - - - - - - - - - - - - - -' '
                                                                 '
      ' Print Ones  - - - - - - - - - - - - - - - - - - - - - -  '
      LOCATE 59, HSpc * (i - Shift) + Clmn0                    ' '
      PRINT USING "#"; i MOD 10;                               ' '
      ' - - - - - - - - - - - - - - - - - - - - - - - - - - - -' '
    END IF                                                       '
  NEXT '---------------------------------------------------------

END SUB
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#40
Quote:Yeah, the fact that it didn't state 'exactly' is why I went with the 'multiple sub-sets in the set' method.

As to skewness, I've never heard it refered to as a curve, rather as a linear progressive offset.

Skewness in my book checks for the "skewness" against the normal distribution.

The formula, if remember correctly is:

Code:
3(Mean-Median)
--------------------
     Std

SCM nice code. Saving this....
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)