Clisp yay
This commit is contained in:
parent
6db0e0618b
commit
55b4986f69
23
common_lisp/2015/1/problem.lisp
Normal file
23
common_lisp/2015/1/problem.lisp
Normal file
@ -0,0 +1,23 @@
|
||||
(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)
|
Loading…
Reference in New Issue
Block a user