From 7f8c33080136f5e221590980a3a2ac04837cefd7 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 17 Oct 2023 14:25:15 +0100 Subject: Use lib.lisp in puzzle-6 --- 2022/puzzle-6.lisp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to '2022') 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)))) -- cgit v1.2.3-13-gbd6f