Created
July 24, 2009 20:44
-
-
Save fffej/154539 to your computer and use it in GitHub Desktop.
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 solve | |
"Solve a system of equations by constraint propagation" | |
[equations known] | |
(dbg :student (format "SOLVE %s %s" equations known)) | |
(or | |
(some (fn [equation] | |
(let [x (one-unknown equation)] | |
(when x | |
(let [answer (solve-arithmetic (isolate equation x))] | |
(solve (postwalk-replace {(:lhs answer) (:rhs answer)} | |
(remove (partial = equation) equations)) | |
(cons answer known)))))) | |
equations) | |
known)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment