Monty Hall problem: Difference between revisions

m (→‎{{header|Perl 6}}: use fix-size array and atomic increment in .race block)
Line 224:
 
=={{header|AutoHotkey}}==
<lang ahk>#NoTrayIconSingleInstance, Force
#SingleInstance, OFF
#Persistent
SetBatchLines, -1
Iterations = 1000
Loop, %Iterations%
Line 244 ⟶ 241:
Incorrect_Stay++
}
Percent_Change := floorround(Correct_Change / Iterations * 100)
Percent_RandomPercent_Stay := floorround(Correct_RandomCorrect_Stay / Iterations * 100)
Percent_StayPercent_Random := floorround(Correct_StayCorrect_Random / 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). ThatsThat's %Percent_Change%`% correct.`r`n`r`nWhen I randomly changed my guess, I got %Correct_Random% of %Iterations% (that's %Incorrect_Random% incorrect). ThatsThat's %Percent_Random%`% correct.`r`n`r`nWhen I stayed with my first guess, I got %Correct_Stay% of %Iterations% (that's %Incorrect_Stay% incorrect). ThatsThat's %Percent_Stay%`% correct.
ExitApp
 
Monty_Hall(Mode) ;Mode is 1 for change, 2 for random, or 3 for stay
{
Random, prizeguess, 1, 3
Random, guessactual, 1, 3
Random, showrand, 1, 32
If (prize = guess && Mode != 3)
 
While show != 0 && show != guess
show := guess = actual ? guess = 3 ? guess - rand : guess = 1 ? guess+rand : guess + 2*rand - 3 : 6 - guess - actual
Random, show, 1, 3
Mode := Mode = 2 ? 2*rand - 1: Mode
Else
Return, Mode = 1 ? show := 6 - prizeguess - show = actual : guess = actual
Random, change_guess, 0, 1
If (Mode = 1 || (change_guess && Mode = 2))
Return, (6 - show - guess) = prize
Else If (Mode = 3 || (!change_guess && Mode = 2))
Return, guess = prize
Else
Return
}</lang>
Sample output:
Line 270 ⟶ 262:
These are the results:
 
When I changed my guess, I got 762659 of 1000 (that's 238341 incorrect). ThatsThat's 7666% correct.
 
When I randomly changed my guess, I got 572 of 1000 (that's 428 incorrect). Thats 57% correct.
When I stayedrandomly withchanged my first guess, I got 329505 of 1000 (that's 671495 incorrect). ThatsThat's 3251% correct.
 
When I randomlystayed changedwith my first guess, I got 572329 of 1000 (that's 428671 incorrect). ThatsThat's 5732% correct.
</pre>