-
-
Save KennyMonster/2cdb391d0f45105b8ab38dab58923063 to your computer and use it in GitHub Desktop.
AOC 2020 Day 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns day-3 | |
(:require [clojure.string :as str])) | |
(def data (-> "input/day_3.txt" | |
(slurp) | |
(str/split-lines))) | |
(defn path [dx dy data] | |
(first | |
(reduce | |
(fn [[result-vec row-index] row] | |
[(conj result-vec (nth (cycle row) row-index)) | |
(+ row-index dx)]) | |
[[] 0] | |
(take-nth dy data)))) | |
(defn tree-count [dx dy data] | |
(count (filter #(= \# %) (drop 1 (path dx dy data))))) | |
(comment | |
(tree-count 3 1 data)) | |
;; part 2 | |
(def slopes [[1 1] | |
[3 1] | |
[5 1] | |
[7 1] | |
[1 2]]) | |
(comment | |
(reduce * (map (fn [[dx dy]] (tree-count dx dy data)) slopes))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment