https://prit.substack.com/p/hackerrank-minimum-absolute-distance
While the following is less efficient, it is more readable (to me), because it manipulates sequences in smaller steps, as opposed to merging those steps into one loop:
(defn minimum-absolute-difference [xs]
(->> (sort xs)
(partition 2 1)
(map (fn [[x y]] (Math/abs (- x y))))
(apply min)))
Also, all classes in java.lang
are imported and referred by ns
. So, you can use Math/abs
in addition to the full name java.lang.Math/abs
it's not ns that does the scoping, but yes, most of java.lang is automatically in scope
I always thought it was ns
. Perhaps i'm confusing the import of java.lang
with the requiring and referring of things in clojure.core
Edit: sorry for the misleading statement earlier.