Last active
December 11, 2019 21:55
-
-
Save lumie1337/a7da80cfdb5ab16fe72b94d4664725c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn terp [mem ip] | |
| (let [[op a b o] (subvec mem ip)] | |
| (if (not= op 99) | |
| (recur | |
| (assoc mem o ((case op 1 + 2 *) (mem a) (mem b))) | |
| (+ ip 4)) | |
| mem)))) | |
| (def mem (vec (read-string (str "[" (slurp "data/day2-input.txt") "]")))) | |
| ; part 1 (same as before) | |
| (-> mem | |
| (assoc 1 12 2 2) | |
| (terp 0) | |
| (get 0)) | |
| ; part 2 | |
| (first (for [noun (range 100), verb (range 100) | |
| :let [[p0] (terp (assoc mem 1 noun 2 verb) 0)] | |
| :when (= p0 19690720)] | |
| (+ (* 100 noun) verb)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment