Created
July 30, 2016 17:29
-
-
Save tiagodavi/175d8cde9a0ac7c2356b827178876459 to your computer and use it in GitHub Desktop.
Divisible Sum Pairs.clj
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 string-to-vector [x] | |
(clojure.string/split x #" ")) | |
(defn to-int [x] | |
(Integer/parseInt x)) | |
(defn divisible? [i j k] | |
(let [i (to-int i) | |
j (to-int j) | |
k (to-int k) | |
] | |
(zero? (rem (+ i j) k)) | |
)) | |
(defn calculate [reference items] | |
(let [total (to-int (first reference)) | |
divisor (second reference) | |
size (range total) | |
] | |
(for [i size | |
j size | |
:when (< i j) | |
:when (divisible? (items i) (items j) divisor) | |
] | |
[i j] | |
))) | |
(def reference (string-to-vector (read-line))) | |
(def items (string-to-vector (read-line))) | |
(println (count (calculate reference items))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment