(asdf:load-system :adventofcode2020) (in-package #:adventofcode2020) (named-readtables:in-readtable :adventofcode2020) (defun tree-collisions (slope tree-map) (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 λ(tree-collisions _ tree-map)) (reduce #'*))))) (def-suite day03) (in-suite day03) (test single-collision-check (is (equal 7 (tree-collisions '(1 3) '("..##......." "#...#...#.." ".#....#..#." "..#.#...#.#" ".#...##..#." "..#.##....." ".#.#.#....#" ".#........#" "#.##...#..." "#...##....#" ".#..#...#.#"))))) (test multiple-collision-check (is (equal '(2 7 3 4 2) (mapcar λ(tree-collisions _ '("..##......." "#...#...#.." ".#....#..#." "..#.#...#.#" ".#...##..#." "..#.##....." ".#.#.#....#" ".#........#" "#.##...#..." "#...##....#" ".#..#...#.#")) '((1 1) (1 3) (1 5) (1 7) (2 1)))))) (run! 'day03)