Skip to content

Instantly share code, notes, and snippets.

@KennyMonster
Created December 3, 2020 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KennyMonster/2cdb391d0f45105b8ab38dab58923063 to your computer and use it in GitHub Desktop.
Save KennyMonster/2cdb391d0f45105b8ab38dab58923063 to your computer and use it in GitHub Desktop.
AOC 2020 Day 3
(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