about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-12-12 21:20:14 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-12-12 21:20:14 +0100
commite294402b6a64c2d09d6bc68f868c43f3ba63ea52 (patch)
tree230c087f605b0b28a709ca0745e3218b86275f58
parent6b8523c3caebdc30f0c2b97efa95d128a95e1744 (diff)
downloadadventofcode2020-e294402b6a64c2d09d6bc68f868c43f3ba63ea52.tar.gz
adventofcode2020-e294402b6a64c2d09d6bc68f868c43f3ba63ea52.tar.xz
adventofcode2020-e294402b6a64c2d09d6bc68f868c43f3ba63ea52.zip
day10
-rw-r--r--day1092
-rw-r--r--day10.clj31
-rw-r--r--day10.ijs3
3 files changed, 126 insertions, 0 deletions
diff --git a/day10 b/day10
new file mode 100644
index 0000000..ccf88b7
--- /dev/null
+++ b/day10
@@ -0,0 +1,92 @@
+17
+110
+146
+144
+70
+57
+124
+121
+134
+12
+135
+120
+19
+92
+6
+103
+46
+56
+93
+65
+14
+31
+63
+41
+131
+60
+73
+83
+71
+37
+85
+79
+13
+7
+109
+24
+94
+2
+30
+3
+27
+77
+91
+106
+123
+128
+35
+26
+112
+55
+97
+21
+100
+88
+113
+117
+25
+82
+129
+66
+11
+116
+64
+78
+38
+99
+130
+84
+98
+72
+50
+36
+54
+8
+34
+20
+127
+1
+137
+143
+76
+69
+111
+136
+53
+43
+140
+145
+49
+122
+18
+42
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
diff --git a/day10.ijs b/day10.ijs
new file mode 100644
index 0000000..9e82b15
--- /dev/null
+++ b/day10.ijs
@@ -0,0 +1,3 @@
+d=:|2-/\3,0x,/:~".;._2(1!:1)<'day10'
+*/#/.~d
+*/>:(<:*-:)@#;._1 d