Skip to content

Instantly share code, notes, and snippets.

Avatar

Jack Warren jack-r-warren

View GitHub Profile
View levenshtein.clj
(defn lev [s t]
"Calculates Levenshtein distance for S and T.
Time complexity is O(|s|*|t|); space complexity is O(|s|).
Uses the swapping two-row method to avoid exponential time, see
https://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_two_matrix_rows"
(let [s-array (char-array s)
t-array (char-array t)
s-length (count s-array)
t-length (count t-array)]
(loop [i 0
@jack-r-warren
jack-r-warren / misc.clj
Created Jul 14, 2020
cond-some*: a combination of Clojure's cond, if-some, and some common if-let* implementations online.
View misc.clj
(defmacro cond-some*
"A combination of cond, if-some, and some common if-let* implementations online.
Behaves like cond except the predicate is some number of bindings which are
available in the second part. Example:
(cond-some*
[my-var-1 true my-var-2 nil] (println \"Won't reach here, any binding to nil
makes the predicate false\")
[a 2 b 3 c false] (println (+ a b)) ;; 5 is printed because false is still
;; non-nil so the predicate is true
View keybase.md

Keybase proof

I hereby claim:

  • I am jack-r-warren on github.
  • I am jackwarren (https://keybase.io/jackwarren) on keybase.
  • I have a public key ASBmTCkSyAlL799siC_z9SeQhNy5M8KOByFf__mL1feoiAo

To claim this, I am signing this object: