Plaster

common-lisp
;;;; 2015.01.02-more-lispy-this-time.lisp ;;;; Advent of Code 2015 Day 1, first attempt in Lisp ;; --------------------------------------------------------------------- ;;; Package Definition ;; --------------------------------------------------------------------- (defpackage :2015-01-02-more-lispy-this-time (:use #:common-lisp)) (in-package :2015-01-02-more-lispy-this-time) ;; --------------------------------------------------------------------- ;;; Definitions ;; --------------------------------------------------------------------- (defconstant +PUZZLE-INPUT-FILE+ "~/proj/Learn/aoc/src/2015.01._PUZZLE-INPUT.txt" "File to be used as input to the program.") (defconstant +PUZZLE-INPUT-STRING+ (uiop:read-file-string +PUZZLE-INPUT-FILE+) "String version of the text in `+PUZZLE-INPUT-FILE+'.") (defconstant +PUZZLE-INPUT-LIST+ (loop for char across +PUZZLE-INPUT-STRING+ collect char) "Puzzle input in lisp list form.") (defconstant +PUZZLE-INPUT-VALUES-LIST+ (mapcar (lambda (INPUT) (cond ((eql INPUT #\() 1) ((eql INPUT #\)) -1))) +PUZZLE-INPUT-LIST+) "Puzzle input converted into floor direction values.") ;; --------------------------------------------------------------------- ;;; Part 1 ;; ------- ;; Santa is trying to deliver presents in a large apartment building, but ;; he can't find the right floor - the directions he got are a little ;; confusing. He starts on the ground floor (floor 0) and then follows ;; the instructions one character at a time. ;; ;; An opening parenthesis, (, means he should go up one floor, and a ;; closing parenthesis, ), means he should go down one floor. ;; ;; The apartment building is very tall, and the basement is very deep; ;; he will never find the top or bottom floors. ;; ;; For example: ;; ;; (()) and ()() both result in floor 0. ;; ((( and (()(()( both result in floor 3. ;; ))((((( also results in floor 3. ;; ()) and ))( both result in floor -1 (the first basement level). ;; ))) and )())()) both result in floor -3. ;; ;; To what floor do the instructions take Santa? ;; --------------------------------------------------------------------- (defun calculate-final-floor (INPUT) ...) (assert (= 138 (calculate-final-floor +PUZZLE-INPUT-VALUES-LIST+)))