Skip to content

Instantly share code, notes, and snippets.

@featheredtoast
Created December 16, 2017 00:50
Show Gist options
  • Save featheredtoast/d7373e5ddf2e60c67a282e4db7b1c3b8 to your computer and use it in GitHub Desktop.
Save featheredtoast/d7373e5ddf2e60c67a282e4db7b1c3b8 to your computer and use it in GitHub Desktop.
(defn parse-input [str]
(->> (clojure.string/split-lines str)
(mapv #(clojure.string/split % #"\s"))))
(defn convert-to-nums [row]
(mapv #(Integer/parseInt %) row))
(defn find-row-diff [row]
(println "finding max of " row)
(- (apply max row) (apply min row)))
(defn find-row-division [row]
(->>
(for [x (range (count row))
y (range (count row))
:when (< x y)]
(let [x-val (nth row x)
y-val (nth row y)]
(cond
(integer? (/ x-val y-val)) (/ x-val y-val)
(integer? (/ y-val x-val)) (/ y-val x-val)
:else nil)))
(keep identity)
first))
(defn spreadsheet-checksum [str]
(->> (parse-input str)
(map convert-to-nums)
#_(map find-row-diff)
(map find-row-division)
(reduce +)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment