Skip to content

Instantly share code, notes, and snippets.

@mishok13
Created July 30, 2015 11:52
Show Gist options
  • Save mishok13/be3e4d93933c259c59b2 to your computer and use it in GitHub Desktop.
Save mishok13/be3e4d93933c259c59b2 to your computer and use it in GitHub Desktop.
Steps in
(defn from-to
"For two integers create a sequence [a, a+x, ..., b, b) where x may be 1 or -1"
[a b]
(let [step (if (pos? (- a b)) -1 1)]
(concat (range a b step) (repeat b))))
(defn from-to-seq
[x y]
(let [max-distance (->> (map - x y) (map #(Math/abs %)) (apply max))]
(->> (map from-to x y)
(map (partial take max-distance))
(apply map vector))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment