X-Git-Url: http://git.jkinsey.net/?p=adventofcode2019.git;a=blobdiff_plain;f=src%2Fadventofcode2019%2Fintcode.clj;fp=src%2Fadventofcode2019%2Fintcode.clj;h=4914fcdda3d71411b8036fc06a5ed5b3c598f7b3;hp=dc542dd17e8240e49ca7a83efc950a092342ba38;hb=b8da8334cb639cbbd04c7a96b1311cb644fdf705;hpb=f1a195aa5c74e264f1aa82aea8556d0501b5abf7 diff --git a/src/adventofcode2019/intcode.clj b/src/adventofcode2019/intcode.clj index dc542dd..4914fcd 100644 --- a/src/adventofcode2019/intcode.clj +++ b/src/adventofcode2019/intcode.clj @@ -68,8 +68,15 @@ ([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))))