Created
December 16, 2022 19:54
-
-
Save schmalz/5fcb201a9cca3c1e7a1418b4360bd766 to your computer and use it in GitHub Desktop.
Advent of Code 2015 - day 1.
This file contains hidden or 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-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