-
Posts
204 -
Joined
-
Last visited
-
Days Won
3
Content Type
Profiles
Forums
Calendar
Gallery
Blogs
Posts posted by jasen
-
-
3 times running the simulation, and I get this result :
0.4985224
0.4985202
0.4985316Even it seems student B winning chance is a bit bigger than student A
-
If anyone understand a bit VBA programming, please check my code, wheather there are some mistake there.
What I do at the simulation is generating random number (1 to 6) twice in each turn,
Let say dice1 = value1 and dice 2 = value2 thanif value1 = 6 and value2 = 6 then Student A win (6+6 = 12)
if value1 + value2 = 7 and lastValue1 + lastValue2 = 7 then student B win
if no winner, I repeat until the winner found.After the winner found, I repeat all the game again 5 million times
After 5 million times I compare student A winning times with student B winning times,
And I find both student have equal chance to winIt take about 10 to 15 second for my computer to do this simulation.
-
Use This simulaton on your microsoft office macro and you will get p = 1/2 as the answer
Use This code in your microsoft office 2010 and you will get p = 1/2
Sub DiceGameTest()
Randomize
Dim NewValue1 As Single
Dim NewValue2 As Single
Dim LastValue1 As Single
Dim LastValue2 As Single
Dim StudentAwin As Single
Dim StudentBwin As Single
Dim Winner As Single
For i = 1 To 5000000
LastValue1 = 0
LastValue2 = 0
Winner = 0
While Winner = 0
LastValue1 = NewValue1
LastValue2 = NewValue2
NewValue1 = Int((6 * Rnd) + 1)
NewValue2 = Int((6 * Rnd) + 1)
If NewValue1 = 6 And NewValue2 = 6 Then Winner = 1
If NewValue1 + NewValue2 = 7 And LastValue1 + LastValue2 = 7 Then Winner = 2
Wend
If Winner = 1 Then StudentAwin = StudentAwin + 1
If Winner = 2 Then StudentBwin = StudentBwin + 1
Winner = 0
Next i
total = StudentBwin + StudentAwin
Selection.TypeText Text:=str(StudentAwin / total)
End Sub
Badminton
in New Logic/Math Puzzles
Posted
Use This Code at microsoft word 2010 macro VBA to test this problem.
Sub BadmintonTest()
Dim JohnWin As Single
Dim JulieWin As Single
Dim P5of9 As Single
Dim P4of7 As Single
Randomize
For i = 1 To 500000
For j = 1 To 9
NewValue = Int((2 * Rnd) + 1)
If NewValue = 1 Then JohnWin = JohnWin + 1
If NewValue = 2 Then JulieWin = JulieWin + 1
If JulieWin = 5 Then P5of9 = P5of9 + 1
Next j
JulieWin = 0
Next i
Selection.TypeText Text:=" percentage 5of9 = " + str(P5of9 / 5000000)
For i = 1 To 500000
For j = 1 To 7
NewValue = Int((2 * Rnd) + 1)
If NewValue = 1 Then JohnWin = JohnWin + 1
If NewValue = 2 Then JulieWin = JulieWin + 1
If JulieWin = 4 Then P4of7 = P4of7 + 1
Next j
JulieWin = 0
Next i
Selection.TypeText Text:=" percentage 4of7 = " + str(P4of7 /I run th 5000000)
End Sub
----------------------
I run the code above and find this result
percentage 5of9 = .0754452 percentage 4of7 = .0727584
percentage 5of9 = .0753496 percentage 4of7 = .072915
percentage 5of9 = .0752444 percentage 4of7 = .0727264
percentage 5of9 = .0751622 percentage 4of7 = .0725046
So it more likely that julie will win 5 out of 9 games than 4 out of 7