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 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))))))) |
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 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 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 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 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 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 check-path-win | |
"Checks a path for a win" | |
[s] | |
(if (apply = s) | |
(first s) | |
nil)) | |
(defn check-win-direction | |
"Checks a sequence of paths in a particular direction for a win" | |
[dir-seq] |
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
; Write a function to determine if two words are anagrams. | |
(defn is-anagram [target src] | |
(if (string? target) | |
(if (= target src) | |
false | |
(is-anagram (frequencies target) src)) | |
(= target (frequencies src)))) | |
; Given a dictionary of words (such as this one), find all of the anagrams for a target word. | |
; Assumption: dictionary of words is a collection |
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 remove-at [n xs] | |
(let [removed (flatten (conj (drop (+ n 1) xs)(take n xs)))] | |
(if (vector? xs) | |
(vec removed) | |
removed))) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> |
NewerOlder