Skip to content

Instantly share code, notes, and snippets.

@roman01la
Last active December 4, 2019 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roman01la/c607849e71e6de11549976428cd3d6a6 to your computer and use it in GitHub Desktop.
Save roman01la/c607849e71e6de11549976428cd3d6a6 to your computer and use it in GitHub Desktop.
AoC 2019, Day 4
(defn increasing? [d]
(re-matches #"1*2*3*4*5*6*7*8*9*" d))
(defn repeating-by? [op s]
(->> (frequencies s)
(some #(op 2 (val %)))))
(defn solve-day4-p1 [from to]
(->> (range from (inc to))
(map str)
(filter #(and (increasing? %) (repeating-by? <= %)))
count))
(defn solve-day4-p2 [from to]
(->> (range from (inc to))
(map str)
(filter #(and (increasing? %) (repeating-by? == %)))
count))
(comment
(= 1767 (solve-day4-p1 145852 616942))
(= 1192 (solve-day4-p2 145852 616942)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment