less than 1 minute read

Code

;; probablistic_computing.clj

(defn rand-binary [num temp]
  (take num (repeatedly #(< (rand) temp))))

(defn true-count [seq]
  (get (frequencies seq) true))

(true-count (rand-binary 1000 0.7))

(defn x [seq1 seq2]
  (map #(and %1 %2) seq1 seq2))

;; small example

(def small-count 10)

(def small-seventy-percent (rand-binary small-count 0.7))

small-seventy-percent

(true-count small-seventy-percent)

(def small-thirty-percent (rand-binary small-count 0.3))

small-thirty-percent

(true-count small-thirty-percent)

(x small-seventy-percent small-thirty-percent)

(true-count
 (x small-seventy-percent small-thirty-percent))


;; large example

(def large-count 10000)

(def seventy-percent (rand-binary large-count 0.7))

(def thirty-percent (rand-binary large-count 0.3))

(true-count seventy-percent)
(true-count thirty-percent)

(true-count
 (x seventy-percent thirty-percent))

Updated: