Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Monty-Hall-problem/Racket/monty-hall-problem.rkt
Normal file
36
Task/Monty-Hall-problem/Racket/monty-hall-problem.rkt
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#lang racket
|
||||
|
||||
(define (get-last-door a b) ; assumes a != b
|
||||
(vector-ref '#(- 2 1
|
||||
2 - 0
|
||||
1 0 -)
|
||||
(+ a (* 3 b))))
|
||||
|
||||
(define (run-game strategy)
|
||||
(define car-door (random 3))
|
||||
(define first-choice (random 3))
|
||||
(define revealed-goat
|
||||
(if (= car-door first-choice)
|
||||
(let ([r (random 2)]) (if (<= car-door r) (add1 r) r)) ; random
|
||||
(get-last-door car-door first-choice))) ; reveal goat
|
||||
(define final-choice (strategy first-choice revealed-goat))
|
||||
(define win? (eq? final-choice car-door))
|
||||
;; (printf "car: ~s\nfirst: ~s\nreveal: ~s\nfinal: ~s\n => ~s\n\n"
|
||||
;; car-door first-choice revealed-goat final-choice
|
||||
;; (if win? 'win 'lose))
|
||||
win?)
|
||||
|
||||
(define (keep-choice first-choice revealed-goat)
|
||||
first-choice)
|
||||
|
||||
(define (change-choice first-choice revealed-goat)
|
||||
(get-last-door first-choice revealed-goat))
|
||||
|
||||
(define (test-strategy strategy)
|
||||
(define N 10000000)
|
||||
(define wins (for/sum ([i (in-range N)]) (if (run-game strategy) 1 0)))
|
||||
(printf "~a: ~a%\n"
|
||||
(object-name strategy)
|
||||
(exact->inexact (/ wins N 1/100))))
|
||||
|
||||
(for-each test-strategy (list keep-choice change-choice))
|
||||
Loading…
Add table
Add a link
Reference in a new issue