aboutsummaryrefslogtreecommitdiff
path: root/2022/Day03/part-one.cl
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2022-12-03 09:49:17 +0200
committerSyndamia <kamen@syndamia.com>2022-12-03 09:49:17 +0200
commit39d5d4f3957971979cf65ad3fa505fb93274c2ee (patch)
treec134731ab25ef70e55fa3cb42908b7d2e66bd4dd /2022/Day03/part-one.cl
parent15aab5d23ae97f4dd498bf3460be1ef22e31f3b5 (diff)
downloadadvent-of-code-39d5d4f3957971979cf65ad3fa505fb93274c2ee.tar
advent-of-code-39d5d4f3957971979cf65ad3fa505fb93274c2ee.tar.gz
advent-of-code-39d5d4f3957971979cf65ad3fa505fb93274c2ee.zip
[2022/D03] Solved both tasks from today
Diffstat (limited to '2022/Day03/part-one.cl')
-rw-r--r--2022/Day03/part-one.cl34
1 files changed, 34 insertions, 0 deletions
diff --git a/2022/Day03/part-one.cl b/2022/Day03/part-one.cl
new file mode 100644
index 0000000..874f893
--- /dev/null
+++ b/2022/Day03/part-one.cl
@@ -0,0 +1,34 @@
+(defvar *prog-input*)
+
+(let ((ui (read-line)))
+ (if (equal ui "")
+ (setq *prog-input* *standard-input*)
+ (setq *prog-input* (open ui))))
+
+(defun char-to-priority (c)
+ (if (and (char<= #\a c) (char<= c #\z))
+ (- (char-int c) 96) ; (+1 (- (char-int c) (char-int #\a))
+ (- (char-int c) 38))) ; (+ 27 (- (char-int c) (char-int #\A))
+
+(let
+ ((inpt (read-line *prog-input* NIL)) (first-comp "") (second-comp "") (encountered '()) (priority-sum 0))
+
+ (loop until (or (string= inpt "end") (not inpt)) do
+ (setq encountered '())
+ (setq first-comp (subseq inpt 0 (/ (length inpt) 2)))
+ (setq second-comp (subseq inpt (/ (length inpt) 2)))
+
+ (loop for itype-first across first-comp do
+ (loop for itype-second across second-comp do
+ (if (and (char= itype-first itype-second) (not (member itype-first encountered)))
+ (progn (push itype-first encountered)
+ (setq priority-sum (+ priority-sum (char-to-priority itype-first)))))))
+
+ (setq inpt (read-line *prog-input* NIL)))
+
+ ;; (print (loop for itype in encountered sum (char-to-priority itype)))
+ (print priority-sum))
+
+(if (not (eq *prog-input* *standard-input*))
+ (close *prog-input*))
+