Created
July 8, 2012 17:19
-
-
Save zdennis/3071882 to your computer and use it in GitHub Desktop.
generating a combination of points
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
; (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