RosettaCodeData/Task/Monty-Hall-problem/APL/monty-hall-problem.apl
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

15 lines
680 B
APL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Run runs;doors;i;chosen;cars;goats;swap;stay;ix;prices
[1] ⍝0: Monthy Hall problem
[2] ⍝1: http://rosettacode.org/wiki/Monty_Hall_problem
[3]
[4] (⎕IO ⎕ML)0 1
[5] prices0 0 1 ⍝ 0=Goat, 1=Car
[6]
[7] ix,/{3?3}¨runs ⍝ random indexes of doors (placement of car)
[8] doors(runs 3)prices[ix] ⍝ matrix of doors
[9] stay+doors[;?3] ⍝ chose randomly one door - is it a car?
[10] swapruns-stay ⍝ If not, then the other one is!
[11]
[12] 'Swap: ',(2100×(swap÷runs)),'% it''s a car'
[13] 'Stay: ',(2100×(stay÷runs)),'% it''s a car'