RosettaCodeData/Task/Monty-Hall-problem/PostScript/monty-hall-problem.ps

37 lines
740 B
PostScript

%!PS
/Courier % name the desired font
20 selectfont % choose the size in points and establish
% the font as the current one
% init random number generator
(%Calendar%) currentdevparams /Second get srand
1000000 % iteration count
0 0 % 0 wins on first selection 0 wins on switch
2 index % get iteration count
{
rand 3 mod % winning door
rand 3 mod % first choice
eq {
1 add
}
{
exch 1 add exch
} ifelse
} repeat
% compute percentages
2 index div 100 mul exch 2 index div 100 mul
% display result
70 600 moveto
(Switching the door: ) show
80 string cvs show (%) show
70 700 moveto
(Keeping the same: ) show
80 string cvs show (%) show
showpage % print all on the page