(in-package #:adventofcode2020)
(defun calc-seat (seat-spec)
- (let ((row (string-right-trim "RL" seat-spec))
- (col (string-left-trim "FB" seat-spec))
- (convert-to-int
- (lambda (str one)
- (loop with len = (1- (length str))
- for c across str
- for i downfrom len
- summing (if (char= c one)
- (ash 1 i) 0)))))
- (mapcar convert-to-int (list row col) '(#\B #\R))))
-
-(defun calc-seat-id (row-col)
- (destructuring-bind (row col) row-col
- (+ (* row 8) col)))
+ (loop with len = (1- (length seat-spec))
+ for c across seat-spec
+ for i downfrom len
+ summing (if (or (char= c #\R) (char= c #\B))
+ (ash 1 i) 0)))
(day 05 input
(let* ((lines (list-from input))
(seat-ids (-<>> lines
- (mapcar (compose #'calc-seat-id #'calc-seat))
+ (mapcar #'calc-seat)
(sort <> #'>))))
(part1 (first seat-ids))
(part2 (loop for big in seat-ids
(test calc-seats
(is (equal
- '((44 5) (70 7) (14 7) (102 4))
+ '(357 567 119 820)
(mapcar #'calc-seat '("FBFBBFFRLR" "BFFFBBFRRR"
"FFFBBBFRRR" "BBFFBBFRLL")))))