Skip to content

Instantly share code, notes, and snippets.

@fffej
Created July 24, 2009 20:44
Show Gist options
  • Save fffej/154539 to your computer and use it in GitHub Desktop.
Save fffej/154539 to your computer and use it in GitHub Desktop.
(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