(asdf:load-system :adventofcode2020)
(in-package #:adventofcode2020)
+(named-readtables:in-readtable fn-reader)
(defun parse-passport (str-list)
(flet ((parser (str)
(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)