X-Git-Url: http://git.jkinsey.net/?p=adventofcode2020.git;a=blobdiff_plain;f=src%2Fday03.lisp;fp=src%2Fday03.lisp;h=093654f6acfe7ba082a2582e3ae957fa3c4e52f5;hp=e708c87565b8bdf730f8f11b4e4276f90493a1b3;hb=a7a78c7ac10e6bb6245dcdeab826f118ca2c60b0;hpb=75918e3330a928fcb91b35255d4115b3f552fa76 diff --git a/src/day03.lisp b/src/day03.lisp index e708c87..093654f 100644 --- a/src/day03.lisp +++ b/src/day03.lisp @@ -1,23 +1,26 @@ (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) @@ -42,17 +45,17 @@ (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)