Created
December 16, 2017 00:50
-
-
Save featheredtoast/d7373e5ddf2e60c67a282e4db7b1c3b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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