Monty Hall problem: Difference between revisions

m (added an image of three doors (one door is open showing a goat) to the task's preamble.)
Line 3,455:
Switching wins 68.80% of the time.
</pre>
 
=={{header|SPAD}}==
{{works with|FriCAS, OpenAxiom, Axiom}}
<lang SPAD>
montyHall(n) ==
wd:=[1+random(3) for j in 1..n]
fc:=[1+random(3) for j in 1..n]
st:=reduce(_+,[1 for j in 1..n | wd.j=fc.j])
p:=(st/n)::DoubleFloat
FORMAT(nil,"stay: ~A, switch: ~A",p,1-p)$Lisp
</lang>
Domain:[http://fricas.github.io/api/Integer.html?highlight=random Integer]
 
{{out}}
<pre>
(1) -> montyHall(1000)
Compiling function montyHall with type PositiveInteger ->
SExpression
 
(1) stay: 0.319, switch: 0.681
Type: SExpression
(2) -> montyHall(10000)
 
(2) stay: 0.3286, switch: 0.6714
Type: SExpression
(3) -> montyHall(100000)
 
(3) stay: 0.33526, switch: 0.66474
Type: SExpression
</pre>
 
 
=={{header|Tcl}}==
Anonymous user