]> code.bitgloo.com Git - clyne/advent-of-code.git/commitdiff
day1: revisit, improve
authorClyne Sullivan <clyne@bitgloo.com>
Mon, 13 Dec 2021 20:20:36 +0000 (15:20 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Mon, 13 Dec 2021 20:20:36 +0000 (15:20 -0500)
day1/part1.clj
day1/part2.clj

index 3316424b9210cad46a198b330830c0c5ef275ff9..1c2c7564f7bff1f1d6c41117f34efba0df7fd23b 100644 (file)
@@ -4,14 +4,12 @@
 ; the previous.
 ;
 
-(->> (slurp "./in")
-     (clojure.string/split-lines)
-     (map read-string)
+(as-> (slurp "./in") $
+     (clojure.string/split-lines $)
+     (map read-string $)
      (reduce
-       #(update [%2 (second %1)] 1 (partial + (if (> %2 (first %1)) 1 0)))
-       [999999 0]
-       )
-     (second)
-     (println)
-     )
+       #(cond-> (assoc %1 0 %2) (> %2 (first %1)) (update 1 inc))
+       [(first $) 0]
+       (rest $))
+     (println (second $)))
 
index b972e1138fcf097d31789a4b08fd12fa13f3542f..e496c7d332694e568c7e2db6635e44cec68c6b87 100644 (file)
@@ -5,25 +5,11 @@
 ; the previous number, and the next number.
 ;
 
-(loop [inc-count 0
-       buff (repeat 4 (Integer/parseInt (read-line)))
-       ]
-  (let [next (read-line)
-        new-count (if (> (last buff) (first buff))
-                    (inc inc-count)
-                    inc-count
-                    )
-        ]
-    (if (empty? next)
-      (println new-count)
-      (recur
-        new-count
-        (concat
-          (rest buff)
-          [(Integer/parseInt next)]
-          )
-        )
-      )
-    )
-  )
+(let [input (->> (slurp "./in")
+                 clojure.string/split-lines
+                 (mapv read-string))]
+  (println
+    (count
+      (filter #(< (get input %) (get input (+ % 3)))
+        (range 0 (- (count input) 3))))))