X-Git-Url: http://git.jkinsey.net/?p=adventofcode2020.git;a=blobdiff_plain;f=src%2Fday04.lisp;fp=src%2Fday04.lisp;h=cb8916f414c0c6a90420d87a6ac4a9e0bfc3a46c;hp=395dea36e1f7efc659859b2acf9c9ebc1f7c25d8;hb=a7a78c7ac10e6bb6245dcdeab826f118ca2c60b0;hpb=75918e3330a928fcb91b35255d4115b3f552fa76 diff --git a/src/day04.lisp b/src/day04.lisp index 395dea3..cb8916f 100644 --- a/src/day04.lisp +++ b/src/day04.lisp @@ -1,5 +1,6 @@ (asdf:load-system :adventofcode2020) (in-package #:adventofcode2020) +(named-readtables:in-readtable fn-reader) (defun parse-passport (str-list) (flet ((parser (str) @@ -15,23 +16,23 @@ (funcall pred value)))) (defparameter *required-field-tests* - (list 'byr (four-digits-test (fn* (<= 1920 _ 2002))) - 'iyr (four-digits-test (fn* (<= 2010 _ 2020))) - 'eyr (four-digits-test (fn* (<= 2020 _ 2030))) - 'hgt (fn* (cl-ppcre:register-groups-bind - ((#'parse-integer value) unit) ("^([0-9]+)(in|cm)$" _) - (cond - ((string= unit "in") (<= 59 value 76)) - ((string= unit "cm") (<= 150 value 193)) - (t nil)))) - 'hcl (fn* (cl-ppcre:scan "^#[0-9a-f]{6}$" _)) - 'ecl (fn* (cl-ppcre:scan "^(amb|blu|brn|gry|grn|hzl|oth)$" _)) - 'pid (fn* (cl-ppcre:scan "^[0-9]{9}$" _)) + (list 'byr (four-digits-test λ(<= 1920 _ 2002)) + 'iyr (four-digits-test λ(<= 2010 _ 2020)) + 'eyr (four-digits-test λ(<= 2020 _ 2030)) + 'hgt λ(cl-ppcre:register-groups-bind + ((#'parse-integer value) unit) ("^([0-9]+)(in|cm)$" _) + (cond + ((string= unit "in") (<= 59 value 76)) + ((string= unit "cm") (<= 150 value 193)) + (t nil))) + 'hcl λ(cl-ppcre:scan "^#[0-9a-f]{6}$" _) + 'ecl λ(cl-ppcre:scan "^(amb|blu|brn|gry|grn|hzl|oth)$" _) + 'pid λ(cl-ppcre:scan "^[0-9]{9}$" _) 'cid (constantly t))) (defun simple-validate-passport (passport) (let ((required-fields '(byr iyr eyr hgt hcl ecl pid))) - (every #'identity (mapcar (fn* (assoc _ passport)) required-fields)))) + (every #'identity (mapcar λ(assoc _ passport) required-fields)))) (defun complex-validate-passport (passport) (flet ((check (pair)