diff --git a/2025/src/day10.clj b/2025/src/day10.clj index 07e375e..86bb031 100644 --- a/2025/src/day10.clj +++ b/2025/src/day10.clj @@ -37,6 +37,9 @@ (apply + (map minimum-button-mashing input)) ;; part 2 +(defn add-expressions [opt type expressions] + (.Add opt (into-array type expressions))) + (->> input (map (fn [{:keys [joltages buttons]}] (let [ctx (Context.) @@ -49,35 +52,26 @@ count range (map #(.mkIntConst ctx (str "j" %))))] - (.Add - opt - (into-array - BoolExpr - (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 %)) - (into-array Expr) - (.mkAdd ctx))] - (.mkEq ctx jn summation-args))))) - (.Add - opt - (into-array - Expr - (for [[idx joltage] (map-indexed vector joltages)] - (let [jn (nth js idx)] - (.mkEq ctx jn (.mkInt ctx (long joltage))))))) - (.Add - opt - (into-array - Expr - (for [b bs] - (.mkGe ctx b (.mkInt ctx (long 0)))))) + (add-expressions opt BoolExpr + (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 %)) + (into-array Expr) + (.mkAdd ctx))] + (.mkEq ctx jn summation-args)))) + (add-expressions opt Expr + (for [[idx joltage] (map-indexed vector joltages)] + (let [jn (nth js idx)] + (.mkEq ctx jn (.mkInt ctx (long joltage)))))) + (add-expressions opt Expr + (for [b bs] + (.mkGe ctx b (.mkInt ctx (long 0))))) (let [^Optimize$Handle mx (.MkMinimize opt (.mkAdd ctx (into-array Expr bs)))] (.Check opt (into-array Expr [])) - (.getInt ^IntNum (.getLower mx)))))) + (.getInt ^IntNum (.getValue mx)))))) (apply +))