From e51b3296d62bbfe40fa31adcaf5a59d050a4b3ea Mon Sep 17 00:00:00 2001 From: ajet Date: Mon, 22 Dec 2025 18:02:29 -0500 Subject: [PATCH] golf --- 2025/src/day10.clj | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/2025/src/day10.clj b/2025/src/day10.clj index 86bb031..f827e6a 100644 --- a/2025/src/day10.clj +++ b/2025/src/day10.clj @@ -1,7 +1,7 @@ (ns day10 (:require [clojure.math.combinatorics :as combo] [input-manager]) - (:import (com.microsoft.z3 BoolExpr Context Expr IntNum Optimize Optimize$Handle))) + (:import (com.microsoft.z3 Context Expr IntNum Optimize Optimize$Handle))) (defn parse-line [line] {:indicators (->> line @@ -37,8 +37,8 @@ (apply + (map minimum-button-mashing input)) ;; part 2 -(defn add-expressions [opt type expressions] - (.Add opt (into-array type expressions))) +(defn add-expressions [opt expressions] + (.Add opt (into-array Expr expressions))) (->> input (map (fn [{:keys [joltages buttons]}] @@ -52,25 +52,22 @@ count range (map #(.mkIntConst ctx (str "j" %))))] - (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))))) + (add-expressions 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 %)) + (into-array Expr) + (.mkAdd ctx))] + (.mkEq ctx jn summation-args)))) + (add-expressions opt (for [[idx joltage] (map-indexed vector joltages)] + (let [jn (nth js idx)] + (.mkEq ctx jn (.mkInt ctx (long joltage)))))) + (add-expressions opt (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 (.getValue mx))))))