blob: 2eeb79946ab94d394d65f83c53258a3752433ae8 (
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
27
28
29
30
31
32
33
|
(load "../src/common.lisp")
(ql:quickload 'uiop :silent t)
(ql:quickload 'cl-ppcre :silent t)
;; 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)))
;;(time (format t "part 2: ~a~%" (part-a (parse-input "../inputs/02.txt"))))
;;(time (format t "part 2: ~a~%" (part-b (parse-input "../inputs/02.txt"))))
|