Created
February 19, 2011 03:46
-
-
Save rhz/834802 to your computer and use it in GitHub Desktop.
This file contains 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
(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) |
This file contains 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
(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