Qbasicnews.com
April 08, 2020, 07:44:36 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2] 3
  Print  
Author Topic: Dice problem  (Read 9096 times)
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #15 on: April 09, 2004, 04:59:12 PM »

Quote from: "Agamemnus"
102.88%


:rotfl:. How did you actually post that? I mean a probability of 100% means you will get that result every time you roll the dice and a probability over 100% is just absurd =P.

Heres my logic:
P(getting the particular side on a 6 sided dice when rolled once) = 1/6
P(5 of 8 dice getting the particular side when rolled once) = 1/6 ^ 5
Thus when the 5 dice are rolled 1000 times the probability would be = 0.12861

PS: P(foo) is read as Probability of foo...

[edit] I too ran a program similar to yours and got the experimental probability as 4.39
Logged
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #16 on: April 09, 2004, 07:55:24 PM »

Quote from: "Agamemnus"
why log?

I don't think it's log.


Well, you need to understand logarithms.  Every iteration of a logarithm, the value gets smaller.  For every die you add, the chances of getting the same number increase by 1/6.  The odds of gettings 5 sides the same are definitely *not* 5/8.

Quote from: "Agamemnus"
Code:
CLS

RANDOMIZE TIMER

FOR k% = 1 TO 50
FOR i% = 1 TO 1000
FOR j% = 1 TO 8
IF INT(RND * 6) = 0 THEN isfour% = isfour% + 1
NEXT j%
IF isfour% = 5 THEN count% = count% + 1
isfour% = 0
NEXT i%
NEXT k%

PRINT count% \ k%


The problem with that is that if more then five sides are four, then it doesn't count them and it should.

If it's 6 sides, there there are 2 sets of 5 combinations.

More accurate code:

Code:
CLS

RANDOMIZE TIMER

FOR k% = 1 TO 50
FOR i% = 1 TO 1000
FOR j% = 1 TO 8
IF INT(RND * 6) = 0 THEN isfour% = isfour% + 1
NEXT j%
IF isfour% >= 5 THEN count% = count% + isfour% - 4
isfour% = 0
NEXT i%
NEXT k%

PRINT count% \ k%
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #17 on: April 10, 2004, 04:00:31 AM »

Quote
The teacher in my computer programming class at the high school asked us to write a program that would find the number of times you would get five sides of 4 on eight 6-sided dice when rolled 1,000 times.


Read the question properly. It clearly states 5 sides. If they wanted  5 or more sides then they would have used the phrase "atleast 5 sides...".

Atleast thats the way we were taught to interpret the probability questions.

Default word = exactly
Atleast = greater than or equal to
Not more than = less than or equal to
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #18 on: April 10, 2004, 11:07:39 AM »

It's not log.

The fact that it's at least 5 sides complicates the matter.

If it said "all of the squares" then it would be a lot simpler.

See my analysis and try to get a different number..
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #19 on: April 10, 2004, 12:08:20 PM »

For atleast 5 sides the solution would differ:

Case i: Exactly five sides
x x x x x o o o
8C5 = 56

Case ii: Six sides
x x x x x x o o
8C6 = 28

Case iii: Seven sides
x x x x x x x o
8C7 = 8

Case iv: Eight sides
x x x x x x x x
8C8 = 1

Thus total no.of occurances of the given condition = 56 * 28 * 8 * 1 = 12,544

Max. combinations = 8P8 = 40,320

P = 12,544 / 40,320 = 0.311111.....

Thus no.of occurances in 1000 trials = 311.11

Is this correct or I suck at probability?  :lol:
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #20 on: April 10, 2004, 04:35:24 PM »

Figured it out.

5: 7000 combinations.
5 or more: 7741 combinations.

1000*7000/1679616 = 4

Code:

FOR i1% = 1 TO 6: FOR i2% = 1 TO 6: FOR i3% = 1 TO 6: FOR i4% = 1 TO 6
FOR i5% = 1 TO 6: FOR i6% = 1 TO 6: FOR i7% = 1 TO 6: FOR i8% = 1 TO 6
tot% = 0
IF i1% = 1 THEN tot% = tot% + 1
IF i2% = 1 THEN tot% = tot% + 1
IF i3% = 1 THEN tot% = tot% + 1
IF i4% = 1 THEN tot% = tot% + 1
IF i5% = 1 THEN tot% = tot% + 1
IF i6% = 1 THEN tot% = tot% + 1
IF i7% = 1 THEN tot% = tot% + 1
IF i8% = 1 THEN tot% = tot% + 1
IF tot% >= 5 THEN n% = n% + 1
NEXT i8%, i7%, i6%, i5%, i4%, i3%, i2%, i1%
PRINT n%
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #21 on: April 10, 2004, 04:37:53 PM »

Quote from: "TheBigBasicQ"
Read the question properly. It clearly states 5 sides. If they wanted  5 or more sides then they would have used the phrase "atleast 5 sides...".


Maybe you should think about it like this:

Take the dice after they roll, without using a set of 5 more then once, how many 5-die combinations of those 8 dice will have all sides egualling 4:

x x x x x x o o

So, we have 2 sets of 5 sides equalling four:

|x x x x x| x o o
x |x x x x x| o o

And *that* is how I interpreted it.

Quote from: "Agamemnus"
It's not log.


You're right, it's not.  But, for an aproximation, log gets a result a hell of a lot closer then your *highly* inaccurate method.
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #22 on: April 10, 2004, 11:50:46 PM »

Bell curve?  You mean "skewness"?

ie.  Right=<0, Left>0, 0 = no skewness
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #23 on: April 13, 2004, 05:31:23 PM »

Now, I mean a bell curve?  Pass grade 10 Algebra and you will understand ;P
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #24 on: April 13, 2004, 05:36:06 PM »

There is no bell curve and there is no log.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #25 on: April 13, 2004, 11:21:46 PM »

There *is* a bell curve, learn some math.
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
speedlemon
I hold this place together
*****
Posts: 874



« Reply #26 on: April 13, 2004, 11:34:35 PM »

there is also a french curve that i used in art class once.
Logged
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #27 on: April 14, 2004, 01:59:57 AM »

Probability was never my strong point, but I use a different method and get different results. To illustrate I'll use a situation with 4 dice where we want exactly 2 of the dice to be fours. The other two dice can be anything except the value four. He are all the possible combinations (x's mark the values that are anything but 4).
Code:

4 4 x x
4 x 4 x
4 x x 4
x 4 4 x
x 4 x 4
x x 4 4


So there a six combinations, this can be worked out for any number using the combinations formula:
Code:

  combs = n! / n! * (n - k)!


Where n is the total number of dice and k is the number of faces we are interested in.

For each of the combinations above, we need to fill in the x's, the x's can be any number except 4 so on a six sided dice there are 5 possible values for each x. In the above example that gives as 5 * 5 for each combination for a total of 150 possible situations where there are 2 fours from 4 dice.

For the 8 dice, 4 fours situation we get:
Code:

  total combinations = 6 ^ 8 =  1679616
 
  combs of four 4's = 8C4 = 70
   
  total combs of four 4's = 8C4 * (5 ^ 4) = 43750

  p(four 4's) = 43750/1679616 = 0.026 = 2.6%


So in 1000 rolls you could expect to get exactly four sides showing 4's around about 2.6%, which is about 26 of the rolls.
Logged

esus saves.... Passes to Moses, shoots, he scores!
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #28 on: April 14, 2004, 02:47:05 AM »

And proof by experiment (quick and dirty method):
Code:

dim dice(8)

total = 0
fours = 0

FOR i1 = 1 TO 6

  FOR i2 = 1 TO 6
    FOR i3 = 1 TO 6
      FOR i4 = 1 TO 6
        FOR i5 = 1 TO 6
          FOR i6 = 1 TO 6
            FOR i7 = 1 TO 6
              FOR i8 = 1 TO 6

                dice(1) = i1
                dice(2) = i2
                dice(3) = i3
                dice(4) = i4
                dice(5) = i5
                dice(6) = i6
                dice(7) = i7
                dice(8) = i8

                total = total + 1

                '**** Check for exactly four 4s ****
                f = 0
                FOR k = 1 TO 8
                  IF dice(k) = 4 THEN f = f + 1
                NEXT
                IF f = 4 THEN fours = fours + 1

              NEXT
            NEXT
          NEXT
        NEXT
      NEXT
    NEXT
  NEXT
NEXT

PRINT "Total: "; total
PRINT "Fours: "; fours


Gives:
Code:

Total: 1679616
Fours: 43750
Logged

esus saves.... Passes to Moses, shoots, he scores!
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #29 on: April 14, 2004, 08:34:37 PM »

That formula can't be right...

It comes out to (n-k)!...
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Pages: 1 [2] 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!