golf
This commit is contained in:
parent
8fa11862e1
commit
14ac947ae3
@ -37,6 +37,9 @@
|
|||||||
(apply + (map minimum-button-mashing input))
|
(apply + (map minimum-button-mashing input))
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
|
(defn add-expressions [opt type expressions]
|
||||||
|
(.Add opt (into-array type expressions)))
|
||||||
|
|
||||||
(->> input
|
(->> input
|
||||||
(map (fn [{:keys [joltages buttons]}]
|
(map (fn [{:keys [joltages buttons]}]
|
||||||
(let [ctx (Context.)
|
(let [ctx (Context.)
|
||||||
@ -49,10 +52,7 @@
|
|||||||
count
|
count
|
||||||
range
|
range
|
||||||
(map #(.mkIntConst ctx (str "j" %))))]
|
(map #(.mkIntConst ctx (str "j" %))))]
|
||||||
(.Add
|
(add-expressions opt BoolExpr
|
||||||
opt
|
|
||||||
(into-array
|
|
||||||
BoolExpr
|
|
||||||
(for [idx (range (count joltages))]
|
(for [idx (range (count joltages))]
|
||||||
(let [jn (nth js idx)
|
(let [jn (nth js idx)
|
||||||
summation-args (->> buttons
|
summation-args (->> buttons
|
||||||
@ -63,21 +63,15 @@
|
|||||||
(map #(nth bs %))
|
(map #(nth bs %))
|
||||||
(into-array Expr)
|
(into-array Expr)
|
||||||
(.mkAdd ctx))]
|
(.mkAdd ctx))]
|
||||||
(.mkEq ctx jn summation-args)))))
|
(.mkEq ctx jn summation-args))))
|
||||||
(.Add
|
(add-expressions opt Expr
|
||||||
opt
|
|
||||||
(into-array
|
|
||||||
Expr
|
|
||||||
(for [[idx joltage] (map-indexed vector joltages)]
|
(for [[idx joltage] (map-indexed vector joltages)]
|
||||||
(let [jn (nth js idx)]
|
(let [jn (nth js idx)]
|
||||||
(.mkEq ctx jn (.mkInt ctx (long joltage)))))))
|
(.mkEq ctx jn (.mkInt ctx (long joltage))))))
|
||||||
(.Add
|
(add-expressions opt Expr
|
||||||
opt
|
|
||||||
(into-array
|
|
||||||
Expr
|
|
||||||
(for [b bs]
|
(for [b bs]
|
||||||
(.mkGe ctx b (.mkInt ctx (long 0))))))
|
(.mkGe ctx b (.mkInt ctx (long 0)))))
|
||||||
(let [^Optimize$Handle mx (.MkMinimize opt (.mkAdd ctx (into-array Expr bs)))]
|
(let [^Optimize$Handle mx (.MkMinimize opt (.mkAdd ctx (into-array Expr bs)))]
|
||||||
(.Check opt (into-array Expr []))
|
(.Check opt (into-array Expr []))
|
||||||
(.getInt ^IntNum (.getLower mx))))))
|
(.getInt ^IntNum (.getValue mx))))))
|
||||||
(apply +))
|
(apply +))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user