aboutsummaryrefslogtreecommitdiff
path: root/2022/puzzle-3.lisp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-07-13 15:33:49 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-07-13 15:33:49 +0100
commit93b8ae46207cf29660fb3c21d34dc45ee872c670 (patch)
tree2d0d9262212808a61a8d7f6262e26a3d12d85c09 /2022/puzzle-3.lisp
parent70e2e26eb15680b0cecdd2ca54d9038c16982df1 (diff)
downloaddotfiles-93b8ae46207cf29660fb3c21d34dc45ee872c670.tar.gz
dotfiles-93b8ae46207cf29660fb3c21d34dc45ee872c670.tar.bz2
dotfiles-93b8ae46207cf29660fb3c21d34dc45ee872c670.zip
(2022)-deleted puzzle files
I think I did this by accident, check out https://git.aryadevchavali.com/advent-of-code/ for my actual advent of code runs.
Diffstat (limited to '2022/puzzle-3.lisp')
-rw-r--r--2022/puzzle-3.lisp67
1 files changed, 0 insertions, 67 deletions
diff --git a/2022/puzzle-3.lisp b/2022/puzzle-3.lisp
deleted file mode 100644
index c5ee3d3..0000000
--- a/2022/puzzle-3.lisp
+++ /dev/null
@@ -1,67 +0,0 @@
-(defvar input (uiop:read-file-string "2022/3-input"))
-
-(defun split-string-in-two (s)
- (let ((len (length s)))
- (list (subseq s 0 (/ len 2)) (subseq s (/ len 2)))))
-
-(defvar inputs (with-input-from-string (s input)
- (loop
- for line = (read-line s nil)
- until (null line)
- collect (split-string-in-two line))))
-
-(defun string-to-clist (str)
- (loop for char across str collect char))
-
-(defun common-types (s1 s2)
- (car (intersection
- (string-to-clist s1)
- (string-to-clist s2))))
-
-(defvar shared (mapcar (lambda (x)
- (destructuring-bind (s1 s2) x
- (common-types s1 s2)))
- inputs))
-
-(defun priority-map (c)
- (if (upper-case-p c)
- (+ 27 (- (char-code c) (char-code #\A)))
- (+ 1 (- (char-code c) (char-code #\a)))))
-
-(defvar round-1-answer (reduce #'+ (mapcar #'priority-map shared)))
-
-;; Round 2
-
-;; Simple recursive algorithm which produces consecutive groups of 3 elements
-(defun group-by-3 (lst)
- (if (null lst)
- nil
- (cons
- (list (car lst) (car (cdr lst)) (car (cdr (cdr lst))))
- (group-by-3 (cdr (cdr (cdr lst)))))))
-
-;; Note the use of group-by-3 here
-(defvar inputs (group-by-3
- (with-input-from-string (s input)
- (loop
- for line = (read-line s nil)
- until (null line)
- collect line))))
-
-;; Extend intersection to three
-(defun common-types-3 (s1 s2 s3)
- (car
- (intersection
- (string-to-clist s1)
- (intersection
- (string-to-clist s2)
- (string-to-clist s3)))))
-
-;; Extend the destructuring bind and use of common-types-3
-(defvar shared (mapcar (lambda (x)
- (destructuring-bind (s1 s2 s3) x
- (common-types-3 s1 s2 s3)))
- inputs))
-
-;; Same as before
-(defvar round-2-answer (reduce #'+ (mapcar #'priority-map shared)))