rename, format

This commit is contained in:
Adam Jeniski 2025-12-12 09:31:42 -10:00
parent d379c21296
commit 56a1bed93d

View File

@ -54,7 +54,7 @@
(def Int z3/Int)
(def Optimize z3/Optimize)
(def Sum z3/Sum)
(defn apply-formulas [opt [f & fs]]
(defn apply-formulas! [opt [f & fs]]
(when f
(! "add" opt f)
(recur opt fs)))
@ -71,24 +71,23 @@
count
range
(map #(Int (str "j" %))))]
(apply-formulas opt (for [idx (range (count joltages))]
(let [jn (nth js idx)
summation-args (->> buttons
(map set)
(map-indexed vector)
(filter #(contains? (second %) idx))
(map first)
(map #(nth bs %)))]
(py= jn (apply Sum summation-args)))))
(apply-formulas opt (for [[idx joltage] (map-indexed vector joltages)]
(let [jn (nth js idx)]
(py= jn joltage))))
(apply-formulas opt (for [b bs] (py>= b 0)))
(apply-formulas! opt (for [idx (range (count joltages))]
(let [jn (nth js idx)
summation-args (->> buttons
(map set)
(map-indexed vector)
(filter #(contains? (second %) idx))
(map first)
(map #(nth bs %)))]
(py= jn (apply Sum summation-args)))))
(apply-formulas! opt (for [[idx joltage] (map-indexed vector joltages)]
(let [jn (nth js idx)]
(py= jn joltage))))
(apply-formulas! opt (for [b bs] (py>= b 0)))
(! "minimize" opt (apply Sum bs))
(! "check" opt)
(let [model (! "model" opt)]
(apply +
(for [b bs]
(! "as_long" (pysubscript model b))))))))
(->> (for [b bs] (! "as_long" (pysubscript model b)))
(apply +))))))
(apply +))