SHARE
TWEET

xmas

jkdufair Nov 14th, 2011 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defrecord Kid [name family-name grandfather-surname])
  2.  
  3. (def kids [
  4.            (Kid. "Alyssa" "Dufair-McKenna" "Dunne")
  5.            (Kid. "Joe" "Dufair-McKenna" "Dunne")
  6.            (Kid. "Rose" "Dufair-McKenna" "Dunne")
  7.            (Kid. "Ian" "Dufair-McKenna" "Dunne")
  8.            (Kid. "Emma" "Dufair-McKenna" "Dunne")
  9.            (Kid. "Jory" "Cook" "Cook")
  10.            (Kid. "Kaitlin" "Dunne" "Dunne")
  11.            (Kid. "Riley" "Dunne" "Dunne")
  12.            (Kid. "Derek" "Cajina" "Rust")
  13.            (Kid. "Cassie" "Carpentier" "Rust")
  14.            (Kid. "Trevor" "Carpentier" "Rust")])
  15.  
  16. (defn is-sibling? [kid1 kid2]
  17.   (= (:family-name kid1) (:family-name kid2)))
  18.  
  19. (defn from-same-grandfather? [kid1 kid2]
  20.   (= (:grandfather-surname kid1) (:grandfather-surname kid2)))
  21.  
  22. (defn is-rust-cousin? [kid1 kid2]
  23.   (and (= (:grandfather-surname kid1) "Rust")
  24.        (= (:grandfather-surname kid2) "Rust")))
  25.  
  26. (defn meets-all-constraints? [kid1 kid2]
  27.   (and (not (is-sibling? kid1 kid2))
  28.        (not (is-rust-cousin? kid1 kid2))))
  29.  
  30. (defn get-constrained-match [kid1 kids]
  31.   (let [kid2 (rand-nth kids)]
  32.     (if (meets-all-constraints? kid1 kid2)
  33.       kid2
  34.       (get-constrained-match kid1 kids))))
  35.  
  36. (defn get-constrained-map [kids1 kids2]
  37.   (if (> (count kids1) 0)
  38.     (let [kid2 (get-constrained-match (first kids1) kids2)]
  39.       (cons [(first kids1) kid2] (get-constrained-map (rest kids1) (remove #{kid2} kids2))))))
  40.  
  41. (defn formatted-constrained-map [kids1 kids2]
  42.   (map (fn [pair] (format "%s -> %s" (:name (first pair)) (:name (second pair)))) (get-constrained-map kids1 kids2)))
  43.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top