src/2020/days/day-01.lisp @ cec05589a84c
2021/14
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 14 Dec 2021 20:19:00 -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 --------------------------------------------------------------------