This file contains hidden or 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 valid-set? [s] | |
(= (sort s) (range 1 10))) | |
(defn rotate [matrix] | |
(apply map list matrix)) | |
(defn rows [matrix] matrix) | |
(defn cols [matrix] (rotate matrix)) |
This file contains hidden or 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 contraindications [meds pairs] | |
(let [meds-set (set (map :rxNorm meds)) | |
contains-pair? (partial every? meds-set)] | |
(->> pairs (filter contains-pair?) not-empty))) |
This file contains hidden or 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 uniques [coll] | |
(let [freqs (frequencies coll)] | |
(filter #(= 1 (get freqs %)) coll))) |
This file contains hidden or 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 factors->string [factors] | |
(->> (frequencies factors) | |
(map (fn [[n exp]] | |
(if (= 1 exp) (str n) (str n "^" exp)))) | |
(interpose " x ") | |
(cons (str (apply * factors) " = ")) | |
(apply str))) |
This file contains hidden or 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 binary-search [target coll] | |
(loop [tree coll] | |
(let [idx (int (/ (count tree) 2)) | |
node (nth tree idx)] | |
(cond | |
(= target node) true | |
(= 1 (count tree)) false | |
(< target node) (recur (subvec tree 0 idx)) | |
(> target node) (recur (subvec tree idx (count tree))))))) |
OlderNewer