Last active
December 3, 2019 16:49
-
-
Save invasionofsmallcubes/27719be4c25872f72e6f884fc46cb15c to your computer and use it in GitHub Desktop.
Advent Of Code - 2019 - DAY 2 - EX 1 #adventOfCode2019
This file contains 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
;; https://adventofcode.com/2019/day/2 | |
(def intcodeProgram []) | |
(defn op | |
[step program instruction] | |
(let [pos1 (nth program (nth program (+ step 1))) | |
pos2 (nth program (nth program (+ step 2))) | |
resultPos (nth program (+ step 3))] | |
(assoc program resultPos (instruction pos1 pos2)))) | |
(defn intcode | |
[program] | |
(let [length (count program)] | |
(loop [step 0 | |
currentProgram program] | |
(let [currentElement (nth currentProgram step)] | |
(case currentElement | |
1 (recur (+ step 4) (op step currentProgram +)) | |
2 (recur (+ step 4) (op step currentProgram *)) | |
99 currentProgram))))) | |
;;(intcode [1 0 0 0 99]) ;; 2,0,0,0,99 | |
;;(intcode [2 3 0 3 99]) ;; 2,3,0,6,99 | |
;;(intcode [2 4 4 5 99 0]) ;; 2,4,4,5,99,9801 | |
;;(intcode [1 1 1 4 99 5 6 0 99]) ;; 30,1,1,4,2,5,6,0,99 | |
(intcode intcodeProgram) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment