Created
August 31, 2018 12:06
-
-
Save anon767/4e7f0b2863e26e8dfd38477d6a7cb881 to your computer and use it in GitHub Desktop.
hackerrank #1 https://www.hackerrank.com/challenges/2d-array
This file contains 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 sum [oneDimArr] | |
(reduce + oneDimArr) | |
) | |
(defn singleHourGlassSum [arr , i , j] | |
(sum | |
(vector | |
(get-in arr [i j]) | |
(get-in arr [i (+ j 1)]) | |
(get-in arr [i (+ j 2)]) | |
(get-in arr [(+ i 1) (+ j 1)]) | |
(get-in arr [(+ i 2) j]) | |
(get-in arr [(+ i 2) (+ j 1)]) | |
(get-in arr [(+ i 2) (+ j 2)]) | |
) | |
) | |
) | |
; Complete the hourglassSum function below. | |
(defn hourglassSum [arr] | |
(let [x (atom [])] | |
(dotimes [i 4] | |
(dotimes [j 4] | |
(swap! x #(vec (concat % (vector (singleHourGlassSum arr i j))))) | |
) | |
) | |
(apply max @x) | |
) | |
) | |
(def fptr (get (System/getenv) "OUTPUT_PATH")) | |
(def arr []) | |
(doseq [_ (range 6)] | |
(def arr (conj arr (vec (map #(Integer/parseInt %) (clojure.string/split (read-line) #" "))))) | |
) | |
(def result (hourglassSum arr)) | |
(spit fptr (str result "\n") :append true) |
c-goetz
commented
Aug 31, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment