Add cl-interpol
[adventofcode2020.git] / src / day05.lisp
CommitLineData
c5ac16de
JK
1(asdf:load-system :adventofcode2020)
2(in-package #:adventofcode2020)
3
4(defun calc-seat (seat-spec)
d1bbb525
JK
5 (loop with len = (1- (length seat-spec))
6 for c across seat-spec
7 for i downfrom len
8 summing (if (or (char= c #\R) (char= c #\B))
9 (ash 1 i) 0)))
c5ac16de
JK
10
11(day 05 input
12 (let* ((lines (list-from input))
13 (seat-ids (-<>> lines
d1bbb525 14 (mapcar #'calc-seat)
c5ac16de
JK
15 (sort <> #'>))))
16 (part1 (first seat-ids))
17 (part2 (loop for big in seat-ids
18 for small in (cdr seat-ids)
19 when (= small (- big 2))
20 return (1+ small)))))
21
22(def-suite day05)
23(in-suite day05)
24
25(test calc-seats
26 (is (equal
d1bbb525 27 '(357 567 119 820)
c5ac16de
JK
28 (mapcar #'calc-seat '("FBFBBFFRLR" "BFFFBBFRRR"
29 "FFFBBBFRRR" "BBFFBBFRLL")))))
30
31(run! 'day05)