advent2022

Advent of Code 2022 Solutions
git clone https://todayiwilllaunchmyinfantsonintoorbit.com/advent2022.git
Log | Files | Refs

1.lisp (935B)


      1 (defpackage #:advent
      2   (:use :cl))
      3 (in-package #:advent)
      4 
      5 (defun asset-path (name &optional ext)
      6   (let* ((this-file #.(or *compile-file-truename* *load-truename*))
      7          (assets-dir (pathname-directory this-file)))
      8     (make-pathname :name name :type ext :directory assets-dir :defaults this-file)))
      9 
     10 (defparameter +input+ (asset-path "input"))
     11 
     12 (defun read-diets ()
     13   (mapcar (lambda (diet) (apply #'+ diet))
     14           (with-open-file (s +input+)
     15             (loop for line = (read-line s nil :eof)
     16                   for diet = new-diet
     17                   for new-diet = (when (and (not (eql line :eof)) (not (string= line "")))
     18                                    (cons (parse-integer line) diet))
     19                   when (not new-diet)
     20                     collect diet
     21                   until (eql line :eof)))))
     22 
     23 (defun solve1 ()
     24   (apply #'max (read-diets)))
     25 
     26 (defun solve2 ()
     27   (apply #'+ (subseq (sort (read-diets) #'>) 0 3)))