aboutsummaryrefslogtreecommitdiff
path: root/2019/02/puzzles.lisp
blob: 9a3acb78fcafa81a1c2286fe340b2aac9959949d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/sbcl --script

(load "../interpreter.lisp")

(defun run-with-noun-and-verb (noun verb ram)
  (setf (aref ram 1) noun
        (aref ram 2) verb)
  (intcode:run ram)
  (aref ram 0))

;; START PART 1
(let ((program (intcode:parse "input")))
  (format t "~d~%" (run-with-noun-and-verb 12 2 program)))
;; END PART 1 START PART 2
(let* ((program (intcode:parse "input"))
       (ram (make-array (length program))))
  (dotimes (noun 100)
    (dotimes (verb 100)
      (loop for i from 0 below (length program)
            do (setf (aref ram i) (aref program i)))
      (when (= (run-with-noun-and-verb noun verb ram) 19690720)
        (format t "~d~%" (+ (* 100 noun) verb))
        (quit)))))
;; END PART 2