From 8d43e37df99f280377bed90284d6ac2428334804 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 30 Nov 2022 19:55:31 -0500 Subject: move 2021 days to folder; update README --- year2021/day1/part1.clj | 15 +++++++++++++++ year2021/day1/part2.clj | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 year2021/day1/part1.clj create mode 100644 year2021/day1/part2.clj (limited to 'year2021/day1') diff --git a/year2021/day1/part1.clj b/year2021/day1/part1.clj new file mode 100644 index 0000000..1c2c756 --- /dev/null +++ b/year2021/day1/part1.clj @@ -0,0 +1,15 @@ +; Day 1, part 1 +; Read a list of numbers from stdin, separated by newlines. +; Count occurances of the current number being greater than +; the previous. +; + +(as-> (slurp "./in") $ + (clojure.string/split-lines $) + (map read-string $) + (reduce + #(cond-> (assoc %1 0 %2) (> %2 (first %1)) (update 1 inc)) + [(first $) 0] + (rest $)) + (println (second $))) + diff --git a/year2021/day1/part2.clj b/year2021/day1/part2.clj new file mode 100644 index 0000000..e496c7d --- /dev/null +++ b/year2021/day1/part2.clj @@ -0,0 +1,15 @@ +; Day 1, part 2 +; Read a list of numbers from stdin, separated by newlines. +; Count occurances of the current sum being greater than +; the previous, where a sum is that of the current number, +; the previous number, and the next number. +; + +(let [input (->> (slurp "./in") + clojure.string/split-lines + (mapv read-string))] + (println + (count + (filter #(< (get input %) (get input (+ % 3))) + (range 0 (- (count input) 3)))))) + -- cgit v1.2.3