Add untested day11pt1
[adventofcode2019.git] / src / adventofcode2019 / intcode.clj
index dc542dd17e8240e49ca7a83efc950a092342ba38..4914fcdda3d71411b8036fc06a5ed5b3c598f7b3 100644 (file)
   ([program settings]
    (merge (build-state program) settings)))
 
+(defn intcode-until [pred state]
+  (as-> (assoc state :step true) it
+        (iterate intcode it)
+        (drop-while #(or (not (:exit %)) (pred %)) it)
+        (first it)
+        (dissoc it :step)))
+
 (defn intcode [{:as state :keys [memory output]}]
    (cond ; quit if :exit, step and return state if :step, else loop
-       (get state :exit) {:memory memory :output output}
+       (get state :exit) {:memory memory :output output :exit true}
        (get state :step) (perform-operation state)
        :else (recur (perform-operation state))))