Monty Hall problem: Difference between revisions
Content added Content deleted
(Added AHK) |
(→{{header|AutoHotkey}}: Added AHK output example) |
||
Line 199: | Line 199: | ||
#Persistent |
#Persistent |
||
SetBatchLines, -1 |
SetBatchLines, -1 |
||
Iterations = |
Iterations = 100 |
||
Loop, %Iterations% |
|||
{ |
|||
If Monty_Hall(1) |
|||
Correct_Change++ |
|||
Else |
|||
Incorrect_Change++ |
|||
If Monty_Hall(2) |
|||
Correct_Random++ |
|||
Else |
|||
Incorrect_Random++ |
|||
If Monty_Hall(3) |
|||
Correct_Stay++ |
|||
Else |
|||
Incorrect_Stay++ |
|||
} |
|||
Percent_Change := floor(Correct_Change / Iterations * 100) |
|||
Percent_Random := floor(Correct_Random / Iterations * 100) |
|||
Percent_Stay := floor(Correct_Stay / Iterations * 100) |
|||
MsgBox,, Monty Hall Problem, These are the results:`r`n`r`nWhen I changed my guess, I got %Correct_Change% of %Iterations% (that's %Incorrect_Change% incorrect). Thats %Percent_Change%`% correct.`r`nWhen I randomly changed my guess, I got %Correct_Random% of %Iterations% (that's %Incorrect_Random% incorrect). Thats %Percent_Random%`% correct.`r`nWhen I stayed with my first guess, I got %Correct_Stay% of %Iterations% (that's %Incorrect_Stay% incorrect). Thats %Percent_Stay%`% correct. |
|||
ExitApp |
|||
Monty_Hall(Mode) ;Mode is 1 for change, 2 for random, or 3 for stay |
|||
{ |
|||
Random, prize, 1, 3 |
|||
Random, guess, 1, 3 |
|||
If (prize = guess && Mode != 3) |
|||
While show != 0 && show != guess |
|||
Random, show, 1, 3 |
|||
Else |
|||
show := 6 - prize - guess |
|||
Random, change_guess, 0, 1 |
|||
If (Mode = 1 || change_guess) |
|||
Return, (6 - show - guess) = prize |
|||
Else If (Mode =#NoTrayIcon |
|||
#SingleInstance, OFF |
|||
#Persistent |
|||
SetBatchLines, -1 |
|||
Iterations = 1000 |
|||
Loop, %Iterations% |
Loop, %Iterations% |
||
{ |
{ |
||
Line 270: | Line 233: | ||
Return, (6 - show - guess) = prize |
Return, (6 - show - guess) = prize |
||
Else If (Mode = 3 || change_guess) |
Else If (Mode = 3 || change_guess) |
||
Return, guess = prize |
|||
Else |
|||
Return |
|||
} 3 || change_guess) |
|||
Return, guess = prize |
Return, guess = prize |
||
Else |
Else |
||
Line 279: | Line 238: | ||
} |
} |
||
</lang> |
</lang> |
||
Sample output: |
|||
<pre> |
|||
These are the results: |
|||
When I changed my guess, I got 75 of 100 (that's 25 incorrect). Thats 75% correct. |
|||
When I randomly changed my guess, I got 43 of 100 (that's 57 incorrect). Thats 43% correct. |
|||
When I stayed with my first guess, I got 66 of 100 (that's 34 incorrect). Thats 66% correct. |
|||
</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |