diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 14:25:15 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 14:25:15 +0100 |
commit | 7f8c33080136f5e221590980a3a2ac04837cefd7 (patch) | |
tree | 5da5f9e913afbd959776b3138d3e6fa28e2c3dd2 /2022 | |
parent | 7daceb30d1f19876af79a617a33792b20d85c028 (diff) | |
download | advent-of-code-7f8c33080136f5e221590980a3a2ac04837cefd7.tar.gz advent-of-code-7f8c33080136f5e221590980a3a2ac04837cefd7.tar.bz2 advent-of-code-7f8c33080136f5e221590980a3a2ac04837cefd7.zip |
Use lib.lisp in puzzle-6
Diffstat (limited to '2022')
-rw-r--r-- | 2022/puzzle-6.lisp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/2022/puzzle-6.lisp b/2022/puzzle-6.lisp index 8869495..7aed004 100644 --- a/2022/puzzle-6.lisp +++ b/2022/puzzle-6.lisp @@ -1,14 +1,14 @@ +(load "lib.lisp") + (defvar input (with-input-from-string (s (uiop:read-file-string "6-input")) (read-line s nil))) (defun is-unique (lst) + "If LST has no duplicates, returns true." (or (null lst) (and (not (member (car lst) (cdr lst))) (is-unique (cdr lst))))) -(defun string-to-list (str) - (loop for char across str collect char)) - (defun first-round (input) (defun calculate-position (nth) "Calculate the actual position of the nth item." @@ -16,7 +16,7 @@ (+ nth 4) nil)) - (let* ((char-list (string-to-list input)) + (let* ((char-list (string-to-clist input)) (unique-check (mapcar (lambda (x y z w) (is-unique (list x y z w))) char-list (cdr char-list) (cdr (cdr char-list)) (cdr (cdr (cdr char-list)))))) (calculate-position (position t unique-check)))) @@ -39,8 +39,7 @@ (+ nth 14) nil)) - - (let* ((char-list (string-to-list input)) + (let* ((char-list (string-to-clist input)) (unique-check (mapcar #'is-unique (successive-by char-list 14)))) (calculate-position (position t unique-check)))) |