aboutsummaryrefslogtreecommitdiff
path: root/2022
diff options
context:
space:
mode:
Diffstat (limited to '2022')
-rw-r--r--2022/puzzle-6.lisp11
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))))