src/2020/days/day-01.lisp @ 2848a4548adf

2023/01 and 2022/01

Also start porting my test data to the new account, since Twitter imploded and
apparently it's impossible for a website to store a goddamn username and
password in The Year of Our Lord 2023 so everyone just outsources auth all
the time, ugh.
author Steve Losh <steve@stevelosh.com>
date Fri, 01 Dec 2023 11:05:43 -0500
parents ff7c8ed35992
children (none)
(advent:defpackage* :advent/2020/01)
(in-package :advent/2020/01)


(defun find-two-addends (seq sum)
  (iterate (for x :in-vector seq :with-index i)
           (iterate (for y :in-vector seq :from (1+ i))
                    (when (= sum (+ x y))
                      (return-from find-two-addends (values x y))))))

(defun find-three-addends (seq sum)
  (iterate (for x :in-vector seq :with-index i)
           (iterate (for y :in-vector seq :from (1+ i) :with-index j)
                    (iterate (for z :in-vector seq :from (1+ j))
                             (when (= sum (+ x y z))
                               (return-from find-three-addends (values x y z)))))))

(define-problem (2020 1) (data read-numbers) (928896 295668576)
  (setf data (coerce data 'vector))
  (values (multiple-value-call #'* (find-two-addends data 2020))
          (multiple-value-call #'* (find-three-addends data 2020))))

#; Scratch --------------------------------------------------------------------