summaryrefslogtreecommitdiffstats
path: root/src/02.lisp
blob: 25d3e4f6333a03a9fad8561828ac4f420195052e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
;; Turn the input file into whatever form you will use for both parts
;; (get-file-lines) and (get-file-string) will be useful
(defun 02/parse-input-direct (input)
  (let ((input (mapcar (lambda (s) (cl-ppcre:split " " s)) input)))
    (mapcar (lambda (x) (cons (intern (string-upcase (CAR x))) (parse-integer (CADR x)))) input)))

(defun 02/parse-input (input-file)
  (02/parse-input-direct (get-file-lines input-file)))

(defun 02/part-a (parsed-input)
  (let ((h 0) (v 0))
    (dolist (i parsed-input)
      (case (car i)
        (forward (incf h (cdr i)))
        (up (decf v (cdr i)))
        (down (incf v (cdr i)))))
    (* h v)))

(defun 02/part-b (parsed-input)
  (let ((h 0) (v 0) (a 0))
    (dolist (i parsed-input)
      (case (car i)
        (forward (progn (incf v (* (cdr i) a)) (incf h (cdr i))))
        (up (decf a (cdr i)))
        (down (incf a (cdr i)))))
    (* h v)))