Skip to content

Instantly share code, notes, and snippets.

@tiagodavi
Created July 30, 2016 17:29
Show Gist options
  • Save tiagodavi/175d8cde9a0ac7c2356b827178876459 to your computer and use it in GitHub Desktop.
Save tiagodavi/175d8cde9a0ac7c2356b827178876459 to your computer and use it in GitHub Desktop.
Divisible Sum Pairs.clj
(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