Skip to content

Instantly share code, notes, and snippets.

@lumie1337
Last active December 11, 2019 21:55
Show Gist options
  • Select an option

  • Save lumie1337/a7da80cfdb5ab16fe72b94d4664725c1 to your computer and use it in GitHub Desktop.

Select an option

Save lumie1337/a7da80cfdb5ab16fe72b94d4664725c1 to your computer and use it in GitHub Desktop.
(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