master
4903000 2 years ago
parent 29afc863d6
commit d06a3008e5

@ -29,3 +29,41 @@
(rec (cdr list) sum)))))
(rec (cdr readings) (reduce #'+ (subseq readings 0 3)))
inc-acc)))
;;; Day 2
(defun setup-solution-2 (stage)
(let ((position (vector 0 0))
(aim 0))
(defun forward (n)
(incf (elt position 0) n)
(if (= stage 2) (incf (elt position 1) (* n aim))))
(defun up (n)
(if (= stage 1)
(decf (elt position 1) n)
(decf aim n)))
(defun down (n)
(if (= stage 1)
(incf (elt position 1) n)
(incf aim n)))
(defun zero ()
(setf position (vector 0 0) aim 0))
(defun result ()
position)))
(defun read-2-1 (file)
(with-open-file (stream file)
(loop for line = (read-line stream nil)
while line
collect (multiple-value-bind (symbol length) (read-from-string line)
(list symbol (parse-integer (subseq line length)))))))
(defun solve-2-1 (data)
(setup-solution-2 1)
(eval (cons 'progn data))
(reduce #'* (result)))
(defun solve-2-2 (data)
(setup-solution-2 2)
(eval (cons 'progn data))
(reduce #'* (result)))

Loading…
Cancel
Save