#| Card draw problem in Racket/Gamble https://www.reddit.com/r/Probability/comments/1gbm4d0/card_draw_problem/ """ I have 100 unique cards. Lets call them card1, card2, card3... etc. If i draw 40 cards from the deck what is the chance of me having both card1 and card2 in my hand? I asked chatgpt and it said 3.8% but my gut feeling tells me thats way too low. Can somone help me out here or is it really 3.8%? """ * importance-sampler (1000000 samples) variable : p #f: 0.842691 #t: 0.157309 mean: 0.157309 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Racket page: http://www.hakank.org/racket/ |# #lang gamble ; (require gamble/viz) (require racket) (require "gamble_utils.rkt") ; (require "gamble_distributions.rkt") (define (model) (; enumerate ; rejection-sampler importance-sampler ; mh-sampler (define n 100) (define m 40) ;; (define x (sort (take (shuffle (range 1 (add1 n))) m) <)) ;; ; (define x (sort (draw-without-replacement m (range 1 (add1 n))) <)) ;; ; (define p (and (= (first x) 1) (= (second x) 2))) ;; (define p (equal? (take x 2) '(1 2))) ; Faster (define x (take (shuffle (range 1 (add1 n))) m)) ; (define x (draw-without-replacement m (range 1 (add1 n)))) (define p (if (and (memv 1 x) (memv 2 x)) #t #f)) (list p) ) ) (show-marginals (model) (list "p" ) #:num-samples 1000000 #:truncate-output 5 ; #:skip-marginals? #t ; #:show-stats? #t ; #:credible-interval 0.84 ; #:hpd-interval (list 0.84) ; #:show-histogram? #t ; #:show-percentiles? #t ; #:burn 0 ; #:thin 0 )