Last active
October 24, 2021 12:59
-
-
Save latant/289d67b0a08e6c043b616d28ddae9047 to your computer and use it in GitHub Desktop.
Calculation on the possibility that there is two dealt card with the distance of 1 in the card game called 'The MInd'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def nnv | |
(memoize | |
(fn [n k] | |
(cond | |
(= k 0) 1 | |
(> (* 2 k) (+ 1 n)) 0 | |
(= (* 2 k) (+ 1 n)) 1 | |
:else (bigint | |
(+ (nnv (dec n) k) | |
(nnv (dec (dec n)) (dec k)))))))) | |
(defn ! [x] | |
(reduce (comp bigint *) | |
(range 1 (inc x)))) | |
(defn c [n k] | |
(/ (! n) | |
(* (! k) | |
(! (- n k))))) | |
(defn p [n k] | |
(->> (/ (nnv n k) | |
(c n k)) | |
(double) | |
(- 1))) | |
; (p 100 18) => 0.9756332632583158 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment