aoc_omni/common_lisp/2015/1/problem.lisp
2025-04-21 18:49:29 -04:00

24 lines
779 B
Common Lisp

(require :uiop)
(defun input-string () (uiop:read-file-string "../../../data/2015/1/input.txt"))
(defun floor-from-next-char (floor char)
(if (char= #\( char) (1+ floor) (if (char= #\) char) (1- floor) floor)))
(defun floor-from-string (string)
(reduce #'floor-from-next-char string :initial-value 0))
(defun steps-from-string (string)
(cdr (reduce (lambda (a b)
(let ((floor (car a))
(steps (cdr a)))
(if (> 0 floor) (cons floor steps)
(cons (floor-from-next-char floor b) (1+ steps)))))
string :initial-value (cons 0 0))))
(defun part-1 () (format t "Part 1: ~a" (floor-from-string (input-string))))
(defun part-2 () (format t "Part 2: ~a" (steps-from-string (input-string))))
(defun solution () (part-1) (terpri) (part-2) (terpri))
(solution)