aboutsummaryrefslogtreecommitdiff
path: root/2022/Day05/part-one.cl
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2022-12-05 13:56:42 +0200
committerSyndamia <kamen@syndamia.com>2022-12-05 13:56:42 +0200
commit3db555e150f915f593800635738c39889d1b403b (patch)
treec3071fd88da329db73e973001d5a5d02175db0d7 /2022/Day05/part-one.cl
parent4390a5c4130668ec6c25ef7f6851ff2aabf4f898 (diff)
downloadadvent-of-code-3db555e150f915f593800635738c39889d1b403b.tar
advent-of-code-3db555e150f915f593800635738c39889d1b403b.tar.gz
advent-of-code-3db555e150f915f593800635738c39889d1b403b.zip
[2022/D05] Solved both tasks from today
Diffstat (limited to '2022/Day05/part-one.cl')
-rw-r--r--2022/Day05/part-one.cl45
1 files changed, 45 insertions, 0 deletions
diff --git a/2022/Day05/part-one.cl b/2022/Day05/part-one.cl
new file mode 100644
index 0000000..914bc06
--- /dev/null
+++ b/2022/Day05/part-one.cl
@@ -0,0 +1,45 @@
+(defvar *prog-input*)
+
+;;; After running file, if you enter a blank line, code will work on each
+;;; line of input, until "end" is typed.
+;;; Otherwise, the input is taken as a filename and code will be executed
+;;; over each line in the file until EOF.
+(let ((ui (read-line)))
+ (if (equal ui "")
+ (setq *prog-input* *standard-input*)
+ (setq *prog-input* (open ui))))
+
+(let
+ ((inpt (read-line *prog-input* NIL)) (i 1) (stacks '(())) (si 0))
+
+ (loop until (char= (char inpt 1) #\1) do
+ (loop until (>= i (length inpt)) do
+ (if (<= (length stacks) si)
+ (setq stacks (append stacks (list NIL NIL) ))) ; ZERO idea why I can't just append '(())
+
+ (if (not (char= (char inpt i) #\Space))
+ (setf (nth si stacks) (append (nth si stacks) (list (char inpt i)))))
+
+ (setq si (+ si 1) i (+ i 4)))
+
+ (setq i 1 si 0)
+ (setq inpt (read-line *prog-input* NIL)))
+
+ (read-line *prog-input* NIL)
+
+ (setq inpt (read-line *prog-input* NIL))
+ (loop until (or (string= inpt "end") (not inpt)) do
+ (setq si (- (parse-integer inpt :junk-allowed T :start (position #\Space inpt :start (position #\f inpt))) 1))
+ (setq i (- (parse-integer inpt :junk-allowed T :start (position #\Space inpt :start (position #\t inpt))) 1))
+
+ (dotimes (x (parse-integer inpt :junk-allowed T :start (position #\Space inpt)))
+ (push (pop (nth si stacks)) (nth i stacks)))
+
+ (setq inpt (read-line *prog-input* NIL)))
+
+ (loop for x in stacks do
+ (prin1 (car x))))
+
+(if (not (eq *prog-input* *standard-input*))
+ (close *prog-input*))
+