adventofcode2022

My solutions for Advent of Code 2022
Log | Files | Refs

day01.lisp (957B)


      1 (defpackage #:adventofcode2022/day01
      2   (:use #:cl #:adventofcode2022))
      3 (in-package #:adventofcode2022/day01)
      4 
      5 (defun task1 (inputs)
      6   (let ((max 0)
      7         (current 0))
      8     (dolist (input inputs)
      9       (if (null input)
     10           (progn
     11             (when (> current max)
     12               (setf max current))
     13             (setf current 0))
     14           (incf current input)))
     15     (when (> current max)
     16       (setf max current))
     17     max))
     18 
     19 (defun task2 (inputs)
     20   (let ((elves nil)
     21         (current 0))
     22     (dolist (input inputs)
     23       (if (null input)
     24           (progn
     25             (push current elves)
     26             (setf current 0))
     27           (incf current input)))
     28     (push current elves)
     29     (setf elves (sort elves #'>))
     30     (apply #'+ (subseq elves 0 3))))
     31 
     32 (define-day 1
     33     (:translate-input (lambda (line)
     34                         (if (= (length line) 0)
     35                             nil
     36                             (parse-integer line))))
     37   #'task1
     38   #'task2)