aboutsummaryrefslogtreecommitdiff
path: root/2022/puzzle-4.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-4.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-4.lisp')
-rw-r--r--2022/puzzle-4.lisp59
1 files changed, 0 insertions, 59 deletions
diff --git a/2022/puzzle-4.lisp b/2022/puzzle-4.lisp
deleted file mode 100644
index 04c7bfb..0000000
--- a/2022/puzzle-4.lisp
+++ /dev/null
@@ -1,59 +0,0 @@
-;; Example input: a-b,c-d which denotes [a,b] and [c,d]
-
-;; We want to find if [c,d] < [a,b] or vice versa (complete inclusion)
-;; and since we're working with integers, it's simply checking if the
-;; bounds are included i.e. c in [a,b] and d in [a,b]
-
-(defvar input (uiop:read-file-string "2022/4-input"))
-
-(defun parse-bound (str)
- "Given STR=\"a-b\" return (a b)"
- (let* ((sep (search "-" str))
- (first (subseq str 0 sep))
- (second (subseq str (+ sep 1))))
- (list (parse-integer first) (parse-integer second))))
-
-(defvar completed-parse
- (with-input-from-string (s input)
- (loop for line = (read-line s nil)
- until (null line)
- collect
- ;; given a-b,c-d we want ((a b) (c d))
- (let* ((sep (search "," line))
- (first-bound (subseq line 0 sep))
- (second-bound (subseq line (+ sep 1))))
- (list (parse-bound first-bound) (parse-bound second-bound))))))
-
-(defun complete-inclusion (first-bound second-bound)
- (destructuring-bind (a b) first-bound
- (destructuring-bind (c d) second-bound
- (or
- (and
- (>= a c) (<= a d)
- (>= b c) (<= b d))
- (and
- (>= c a) (<= c b)
- (>= d a) (<= d b))))))
-
-(defvar round-1-answer (length (remove-if #'null
- (mapcar (lambda (pair)
- (destructuring-bind (first second) pair
- (complete-inclusion first second)))
- completed-parse))))
-
-;; Round 2: any overlap at all. Basically just overhaul the inclusion
-;; function and then do the same answer checking.
-(defun any-inclusion (first second)
- (destructuring-bind (a b) first
- (destructuring-bind (c d) second
- ;; How about doing this through negation? [a,b] does not overlap with [c,d] at all if either b < c or a > d.
- (not
- (or
- (< b c)
- (> a d))))))
-
-(defvar round-2-answer (length (remove-if #'null
- (mapcar (lambda (pair)
- (destructuring-bind (first second) pair
- (any-inclusion first second)))
- completed-parse))))