re: AoC Day 1: Chronal Calibration VIEW POST

FULL DISCUSSION
 

Clojure:

(utils/read-file just slurps and splits by newlines)

Part 1:

(->>
  (utils/read-file (str utils/resources-path "day1.txt"))
  (map #(Integer. ^String %))
  (apply +))

Part 2:

(->>
   (utils/read-file (str utils/resources-path "day1.txt"))
   (map #(Integer. ^String %))
   (cycle)
   (reduce
     (fn [{:keys [freq seen]} freq-change]
       (if (seen freq)
         (reduced freq)
         {:freq (+ freq freq-change) :seen (conj seen freq)}))
     {:freq 0 :seen #{}}))
code of conduct - report abuse