Skip to content

Instantly share code, notes, and snippets.

@foobar27
Created May 23, 2012 21:23
Show Gist options
  • Save foobar27/2777922 to your computer and use it in GitHub Desktop.
Save foobar27/2777922 to your computer and use it in GitHub Desktop.
Clojure Dynamic Programming DSL
(defn fib [n]
(dynamic [n]
0 0
1 1
n (let-recur [a (- n 1)
b (- n 2)]
(+ a b))))
(defn edit-distance [s1 s2]
(dynamic [(.length s1) (.length s2)]
[0 j] j
[i 0] i
[i j] (let-recur [a [i (dec j)]
b [(dec i) j]
c [(dec i) (dec j)]]
(+ c (if (= (.charAt s1 i) (.charAt s2 j)) 0 1)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment