day1: revisit, improve

master
Clyne 3 years ago
parent 8ada5e0331
commit 9b0982ba81

@ -4,14 +4,12 @@
; the previous. ; the previous.
; ;
(->> (slurp "./in") (as-> (slurp "./in") $
(clojure.string/split-lines) (clojure.string/split-lines $)
(map read-string) (map read-string $)
(reduce (reduce
#(update [%2 (second %1)] 1 (partial + (if (> %2 (first %1)) 1 0))) #(cond-> (assoc %1 0 %2) (> %2 (first %1)) (update 1 inc))
[999999 0] [(first $) 0]
) (rest $))
(second) (println (second $)))
(println)
)

@ -5,25 +5,11 @@
; the previous number, and the next number. ; the previous number, and the next number.
; ;
(loop [inc-count 0 (let [input (->> (slurp "./in")
buff (repeat 4 (Integer/parseInt (read-line))) clojure.string/split-lines
] (mapv read-string))]
(let [next (read-line) (println
new-count (if (> (last buff) (first buff)) (count
(inc inc-count) (filter #(< (get input %) (get input (+ % 3)))
inc-count (range 0 (- (count input) 3))))))
)
]
(if (empty? next)
(println new-count)
(recur
new-count
(concat
(rest buff)
[(Integer/parseInt next)]
)
)
)
)
)

Loading…
Cancel
Save