Created
June 27, 2013 01:18
-
-
Save zfogg/5873244 to your computer and use it in GitHub Desktop.
A lazy sequence of the Pythagorean Triples.
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
(defn t1 | |
[[a b c]] | |
[($= 1 * a - 2 * b + 2 * c) | |
($= 2 * a - 1 * b + 2 * c) | |
($= 2 * a - 2 * b + 3 * c)]) | |
(defn t2 | |
[[a b c]] | |
[($= 1 * a + 2 * b + 2 * c) | |
($= 2 * a + 1 * b + 2 * c) | |
($= 2 * a + 2 * b + 3 * c)]) | |
(defn t3 | |
[[a b c]] | |
[($= -1 * a + 2 * b + 2 * c) | |
($= -2 * a + 1 * b + 2 * c) | |
($= -2 * a + 2 * b + 3 * c)]) | |
(defn ts | |
[abc] | |
[(t1 abc) (t2 abc) (t3 abc)]) | |
(defn lazy-mapcat | |
[f coll] | |
(lazy-seq | |
(if (not-empty coll) | |
(concat | |
(f (first coll)) | |
(lazy-mapcat f (rest coll)))))) | |
(def pythTrips | |
(lazy-cat [[3 4 5]] (lazy-mapcat ts pythTrips))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment