src/2020/days/day-02.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/02)
(in-package :advent/2020/02)
(defun parse-line (line)
(ppcre:register-groups-bind
((#'parse-integer i j) char password)
("(\\d+)-(\\d+) (.): (.+)" line)
(values i j (coerce char 'character) password)))
(defun validp-1 (min max char password)
(<= min (count char password) max))
(defun validp-2 (i j char password)
(alexandria:xor (char= char (aref password (1- i)))
(char= char (aref password (1- j)))))
(define-problem (2020 2) (data) (655 673)
(iterate (for line :in-stream data :using #'read-line)
(for (values i j char password) = (parse-line line))
(counting (validp-1 i j char password) :into p1)
(counting (validp-2 i j char password) :into p2)
(returning p1 p2)))
#; Scratch --------------------------------------------------------------------