Skip to content

Instantly share code, notes, and snippets.

@KennyMonster
Created Dec 3, 2020
Embed
What would you like to do?
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