Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,15 @@
(defun make-round ()
(let ((array (make-array 3
:element-type 'bit
:initial-element 0)))
(setf (bit array (random 3)) 1)
array))
(defun show-goat (initial-choice array)
(loop for i = (random 3)
when (and (/= initial-choice i)
(zerop (bit array i)))
return i))
(defun won? (array i)
(= 1 (bit array i)))

View file

@ -0,0 +1,18 @@
CL-USER> (progn (loop repeat #1=(expt 10 6)
for round = (make-round)
for initial = (random 3)
for goat = (show-goat initial round)
for choice = (loop for i = (random 3)
when (and (/= i initial)
(/= i goat))
return i)
when (won? round (random 3))
sum 1 into result-stay
when (won? round choice)
sum 1 into result-switch
finally (progn (format t "Stay: ~S%~%" (float (/ result-stay
#1# 1/100)))
(format t "Switch: ~S%~%" (float (/ result-switch
#1# 1/100))))))
Stay: 33.2716%
Switch: 66.6593%

View file

@ -0,0 +1,14 @@
;Find out how often we win if we always switch
(defun rand-elt (s)
(elt s (random (length s))))
(defun monty ()
(let* ((doors '(0 1 2))
(prize (random 3));possible values: 0, 1, 2
(pick (random 3))
(opened (rand-elt (remove pick (remove prize doors))));monty opens a door which is not your pick and not the prize
(other (car (remove pick (remove opened doors))))) ;you decide to switch to the one other door that is not your pick and not opened
(= prize other))) ; did you switch to the prize?
(defun monty-trials (n)
(count t (loop for x from 1 to n collect (monty))))