Skip to content

Instantly share code, notes, and snippets.

@rhz
Created February 19, 2011 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhz/834802 to your computer and use it in GitHub Desktop.
Save rhz/834802 to your computer and use it in GitHub Desktop.
(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