about summary refs log tree commit diff
path: root/day01.clj
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-12-02 12:43:18 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-12-02 12:43:18 +0100
commit9a76ba31c25d5adfacc41d5c7282fc48fe1113a6 (patch)
tree4e6568c4ef526a71370e6b9c47101e78f193418a /day01.clj
parent51f7210420ca4d6b9e6da1c058340fc871885ca9 (diff)
downloadadventofcode2021-9a76ba31c25d5adfacc41d5c7282fc48fe1113a6.tar.gz
adventofcode2021-9a76ba31c25d5adfacc41d5c7282fc48fe1113a6.tar.xz
adventofcode2021-9a76ba31c25d5adfacc41d5c7282fc48fe1113a6.zip
day01
Diffstat (limited to 'day01.clj')
-rw-r--r--day01.clj22
1 files changed, 22 insertions, 0 deletions
diff --git a/day01.clj b/day01.clj
new file mode 100644
index 0000000..c9751f3
--- /dev/null
+++ b/day01.clj
@@ -0,0 +1,22 @@
+(ns org.vuxu.aoc2021.day01
+  (:require [clojure.string :as str]))
+
+(def data
+  (->> (slurp "day01")
+       (str/split-lines)
+       (map parse-long)))
+
+(def part1
+  (->> data
+       (partition 2 1)
+       (filter (partial apply <))
+       count))
+
+part1 ;; => 1688
+
+(def part2
+  (->> (map vector data (drop 3 data))      ; a+b+c < b+c+d <==> a < d
+       (filter (partial apply <))
+       count))
+
+part2 ;; => 1728