]>
Commit | Line | Data |
---|---|---|
1 | (asdf:load-system :adventofcode2020) | |
2 | (in-package #:adventofcode2020) | |
3 | ||
4 | (defun calc-seat (seat-spec) | |
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))) | |
10 | ||
11 | (day 05 input | |
12 | (let* ((lines (list-from input)) | |
13 | (seat-ids (-<>> lines | |
14 | (mapcar #'calc-seat) | |
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 | |
27 | '(357 567 119 820) | |
28 | (mapcar #'calc-seat '("FBFBBFFRLR" "BFFFBBFRRR" | |
29 | "FFFBBBFRRR" "BBFFBBFRLL"))))) | |
30 | ||
31 | (run! 'day05) |