Skip to content

Instantly share code, notes, and snippets.

@death
Created December 1, 2021 05:29
aoc2021-day1
;;;; +----------------------------------------------------------------+
;;;; | Advent of Code 2021 |
;;;; +----------------------------------------------------------------+
(defpackage #:snippets/aoc2021/day1
(:use #:cl)
(:export
#:day1))
(in-package #:snippets/aoc2021/day1)
(defun count-increasing-sums (input k)
(do ((c 0)
(n (- (length input) k))
(s1 (reduce #'+ input :end k))
(i 0 (1+ i)))
((= i n) c)
(let ((s2 (+ (- s1 (aref input i)) (aref input (+ i k)))))
(when (> s2 s1)
(incf c))
(setf s1 s2))))
(defun day1 (input)
(let ((vector (coerce input 'vector)))
(list (count-increasing-sums vector 1)
(count-increasing-sums vector 3))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment