(asdf:load-system :adventofcode2020)
(in-package #:adventofcode2020)
+(named-readtables:in-readtable fn-reader)
(defun tree-collisions (slope tree-map)
- (destructuring-bind (rise run) slope
- (loop with terrain-width = (-> tree-map first length)
- for i upfrom 0 by run
- for j upfrom 0
- for terrain-line in tree-map
- when (->> rise (mod j) (= 0))
- counting (->> terrain-width
- (mod i)
- (char terrain-line)
- (char= #\#)))))
+ (loop with (rise run) = slope
+ with proper-map = (loop for j upfrom 0
+ for line in tree-map
+ when (->> rise (mod j) (= 0))
+ collecting line)
+ with terrain-width = (-> tree-map first length)
+ for i upfrom 0 by run
+ for terrain-line in proper-map
+ counting (->> terrain-width
+ (mod i)
+ (char terrain-line)
+ (char= #\#))))
(day 03 input
(let ((tree-map (list-from input)))
(part1 (tree-collisions '(1 3) tree-map))
(part2 (->> '((1 1) (1 3) (1 5) (1 7) (2 1))
- (mapcar (fn* (tree-collisions _ tree-map)))
+ (mapcar λ(tree-collisions _ tree-map))
(reduce #'*)))))
(def-suite day03)
(test multiple-collision-check
(is (equal
'(2 7 3 4 2)
- (mapcar (fn* (tree-collisions _ '("..##......."
- "#...#...#.."
- ".#....#..#."
- "..#.#...#.#"
- ".#...##..#."
- "..#.##....."
- ".#.#.#....#"
- ".#........#"
- "#.##...#..."
- "#...##....#"
- ".#..#...#.#")))
+ (mapcar λ(tree-collisions _ '("..##......."
+ "#...#...#.."
+ ".#....#..#."
+ "..#.#...#.#"
+ ".#...##..#."
+ "..#.##....."
+ ".#.#.#....#"
+ ".#........#"
+ "#.##...#..."
+ "#...##....#"
+ ".#..#...#.#"))
'((1 1) (1 3) (1 5) (1 7) (2 1))))))
(run! 'day03)
(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)
(asdf:load-system :adventofcode2020)
(in-package #:adventofcode2020)
+(named-readtables:in-readtable fn-reader)
(day 00 input
(let ((lines (list-from input)))
(split "\\n" str))
(defun int-list-from (str)
- (mapcar #'parse-integer (split "\\n" str)))
+ (mapcar #'parse-integer (list-from str)))
(defun cartesian-product (A B &rest C)
(let ((helper (lambda (X Y)