Skip to content

Instantly share code, notes, and snippets.

@zdennis
Created July 8, 2012 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdennis/3071882 to your computer and use it in GitHub Desktop.
Save zdennis/3071882 to your computer and use it in GitHub Desktop.
generating a combination of points
; (points-from-x-and-ys 1 [1 0 -1]) # => [[1 1] [1 0] [1 -1]]
(defn points-from-x-and-ys [x ys]
(loop [ysleft ys results []]
(if (empty? ysleft)
results
(recur
(rest ysleft)
(conj results (point/create x (first ysleft)))))))
; generate a list of all possible points that can be moved given a set of possible x's and y's
(defn directions [xs ys]
(loop [xsleft [-1 0 1] results []]
(if (empty? xsleft)
results
(recur
(rest xsleft)
(conj results (points-from-x-and-ys (first xsleft) ys))))))
; usage
(directions [-1 0 1] [-1 0 1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment