Skip to content

Instantly share code, notes, and snippets.

@schmalz
Created December 16, 2022 19:54
Show Gist options
  • Save schmalz/5fcb201a9cca3c1e7a1418b4360bd766 to your computer and use it in GitHub Desktop.
Save schmalz/5fcb201a9cca3c1e7a1418b4360bd766 to your computer and use it in GitHub Desktop.
Advent of Code 2015 - day 1.
(ns day-1.core)
(def input (slurp "input.txt"))
(def up \()
(defn where-is-santa
"What floor will Santa finish on after following INSTRUCTIONS?"
[instructions]
(reduce #(+ %1
(if (= %2 up)
1
-1))
0
instructions))
(defn first-basement-floor
"The index of the first instruction in INSTRUCTIONS that mean that Santa goes
into a basement floor."
[instructions]
(loop [floor 0
i instructions
c 0]
(if (= floor -1)
c
(recur (+ floor
(if (= (first i) up)
1
-1))
(rest i)
(inc c)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment