Skip to content

Instantly share code, notes, and snippets.

@rhz

rhz/gist:834802

Created Feb 19, 2011
Embed
What would you like to do?
(defn prob-n [pred tol in n] ;; in is a csv's filename
(let [as (for [[_ _ p m] (map #(.split % ";") (rest (.split (slurp in) "\n"))) :when p]
(if (empty? m) [p] [p m])) ;; take the third and fourth (if possible) column of each row
conteo (for [as (c/combinations as n)]
(if (apply pred tol as) 1 0))]
(/ (reduce + conteo) (count conteo))))
(defn ningun-apellido-en-comun [tol & as]
(let [distinct-as (distinct (apply concat as))
conteo (for [a distinct-as]
(count (filter #(some #{a} %) as)))]
(<= (- (reduce + conteo) (count distinct-as)) tol)))
user=> (prob-n ningun-apellido-en-comun 0 "some.csv" 20)
(defn prob-n [pred tol in n]
(let [as (for [line (rest (.split (slurp in) "\n"))
:let [as (distinct (filter seq (take 2 (drop 2 (.split line ";")))))]
:when (seq as)] as)
conteo (for [as (c/combinations as n)]
(if (apply pred tol as) 1 0))]
(/ (reduce + conteo) (count conteo))))
(defn ningun-apellido-en-comun [tol & as]
(let [freqs (frequencies as)]
(<= (- (reduce + (vals freqs)) (count (keys freqs))) tol)))
user=> (prob-n ningun-apellido-en-comun 0 "some.csv" 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.