projects
/
adventofcode2020.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
c5ac16d
)
Update day 05 with shorter solution
author
Jack Kinsey
<j.jameskinsey@gmail.com>
Sun, 6 Dec 2020 00:02:43 +0000
(19:02 -0500)
committer
Jack Kinsey
<j.jameskinsey@gmail.com>
Sun, 6 Dec 2020 00:02:43 +0000
(19:02 -0500)
Thanks, SSCDCS.
src/day05.lisp
patch
|
blob
|
blame
|
history
diff --git
a/src/day05.lisp
b/src/day05.lisp
index ee60cd2e80b036429559e35dc0b616a1d4f79253..214553a3abd6f794efe74d11137882189660c27d 100644
(file)
--- a/
src/day05.lisp
+++ b/
src/day05.lisp
@@
-2,25
+2,16
@@
(in-package #:adventofcode2020)
(defun calc-seat (seat-spec)
(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
(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
(sort <> #'>))))
(part1 (first seat-ids))
(part2 (loop for big in seat-ids
@@
-33,7
+24,7
@@
(test calc-seats
(is (equal
(test calc-seats
(is (equal
- '(
(44 5) (70 7) (14 7) (102 4)
)
+ '(
357 567 119 820
)
(mapcar #'calc-seat '("FBFBBFFRLR" "BFFFBBFRRR"
"FFFBBBFRRR" "BBFFBBFRLL")))))
(mapcar #'calc-seat '("FBFBBFFRLR" "BFFFBBFRRR"
"FFFBBBFRRR" "BBFFBBFRLL")))))