projects
/
adventofcode2019.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add untested day11pt1
[adventofcode2019.git]
/
src
/
adventofcode2019
/
intcode.clj
diff --git
a/src/adventofcode2019/intcode.clj
b/src/adventofcode2019/intcode.clj
index dc542dd17e8240e49ca7a83efc950a092342ba38..4914fcdda3d71411b8036fc06a5ed5b3c598f7b3 100644
(file)
--- a/
src/adventofcode2019/intcode.clj
+++ b/
src/adventofcode2019/intcode.clj
@@
-68,8
+68,15
@@
([program settings]
(merge (build-state program) settings)))
([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
(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))))
(get state :step) (perform-operation state)
:else (recur (perform-operation state))))