Monty Hall problem: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 9:
 
=={{header|ActionScript}}==
<lang actionscript>
package {
import flash.display.Sprite;
Line 44:
}
}
</lang>
</actionscript>
Output:
<pre>
Line 211:
{{works with|QuickBasic|4.5}}
{{trans|Java}}
<lang qbasic>RANDOMIZE TIMER
DIM doors(3) '0 is a goat, 1 is a car
CLS
Line 231:
NEXT plays
PRINT "Switching wins"; switchWins; "times."
PRINT "Staying wins"; stayWins; "times."</qbasiclang>
Output:
<pre>Switching wins 21805 times.
Line 239:
=={{header|C}}==
 
<lang c>#include <stdio.h>
#include <stdlib.h>
 
Line 302:
printf("New random choice: %.2f\n", PERCENT(randomwinning) );
}
</clang>
 
Output of one run:
Line 451:
 
=={{header|Java}}==
<lang java>import java.util.Random;
public class Monty{
public static void main(String[] args){
Line 476:
System.out.println("Staying wins " + stayWins + " times.");
}
}</javalang>
Output:
<pre>Switching wins 21924 times.
Line 514:
 
=={{header|OCaml}}==
<lang ocaml>let trials = 10000
 
type door = Car | Goat
Line 542:
strat (100. *. (float n /. float trials)) in
msg "switch" switch;
msg "stay" stay</ocamllang>
 
 
=={{header|Perl}}==
 
<lang perl>#! /usr/bin/perl
use strict;
my $trials = 10000;
Line 589:
print "Stay win ratio " . (100.0 * $stay/$trials) . "\n";
print "Switch win ratio " . (100.0 * $switch/$trials) . "\n";
exit 0;</perllang>
 
=={{header|Python}}==
<lang python>
'''
I could understand the explanation of the Monty Hall problem
Line 638:
for x in range(iterations)].count(True),
print "out of", iterations, "times.\n"
</pythonlang>
Sample output:
<pre>Monty Hall problem simulation:
Line 748:
 
=={{header|Scheme}}==
<lang scheme>
(define (random-from-list list) (list-ref list (random (length list))))
(define (random-permutation list)
Line 816:
;; (stay-strategy won with probability 33.3638 %
;; and switch-strategy won with probability 51.8763 %)
</schemelang>
 
=={{header|Vedit macro language}}==