Created
May 23, 2012 21:23
-
-
Save foobar27/2777922 to your computer and use it in GitHub Desktop.
Clojure Dynamic Programming DSL
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 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