Created
September 5, 2023 20:45
-
-
Save ekoontz/6dcc5d793cfcce4182e44079fd6060cb to your computer and use it in GitHub Desktop.
probability of reaching m heads given n coin tosses
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
(let [n 10 | |
m 5 | |
expt (clojure.math.numeric-tower/expt 2 n) | |
number-of-heads (->> (range expt) | |
(map (fn [i] (count (re-seq #"1" (Integer/toBinaryString i))))) | |
(filter #(or (>= % m))) | |
count)] | |
[expt number-of-heads (+ 0.0 (/ number-of-heads expt))]) | |
[1024 638 0.623046875] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment