diff options
author | Leah Neukirchen <leah@vuxu.org> | 2020-12-12 21:20:14 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2020-12-12 21:20:14 +0100 |
commit | e294402b6a64c2d09d6bc68f868c43f3ba63ea52 (patch) | |
tree | 230c087f605b0b28a709ca0745e3218b86275f58 /day10.clj | |
parent | 6b8523c3caebdc30f0c2b97efa95d128a95e1744 (diff) | |
download | adventofcode2020-e294402b6a64c2d09d6bc68f868c43f3ba63ea52.tar.gz adventofcode2020-e294402b6a64c2d09d6bc68f868c43f3ba63ea52.tar.xz adventofcode2020-e294402b6a64c2d09d6bc68f868c43f3ba63ea52.zip |
day10
Diffstat (limited to 'day10.clj')
-rw-r--r-- | day10.clj | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/day10.clj b/day10.clj new file mode 100644 index 0000000..255ba27 --- /dev/null +++ b/day10.clj @@ -0,0 +1,31 @@ +(def data + (->> (slurp "day10") + (clojure.string/split-lines) + (map read-string) + vec)) + +(def diff + (->> data + (#(cons 0 %)) + (#(cons (+ 3 (reduce max %)) %)) + sort + (#(map - (rest %) %)))) + +(->> diff + frequencies + (#(map % [1 3])) + (apply *)) ; => 1820 + +(->> diff + (partition-by identity) + (filter #(= (first %) 1)) + (map count) + (map #(inc (* (dec %) (/ % 2)))) ; http://oeis.org/A000124 + (apply *)) ; => 3454189699072N + +;; => (1 3 1 1 1 3 1 1 3 1 3 3) +;; 1 4 2 1 +;; +;; => (1 1 1 1 3 1 1 1 1 3 3 1 1 1 3 1 1 3 3 1 1 1 1 3 1 3 3 1 1 1 1 3) +;; 7 7 4 2 7 1 7 +;; 19208: 2 2 2 7 7 7 7 |