diff options
Diffstat (limited to 'examples/pythagorean-triples.scm')
-rw-r--r-- | examples/pythagorean-triples.scm | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/examples/pythagorean-triples.scm b/examples/pythagorean-triples.scm new file mode 100644 index 0000000..4f620af --- /dev/null +++ b/examples/pythagorean-triples.scm @@ -0,0 +1,11 @@ +(import (srfi 41) + (prefix (algebraic-structures stream monad) stream:) + (prefix (algebraic-structures stream alternative) stream:)) + +(define (pythagorean-triples) + (stream:do (b <- (stream-from 1)) + (a <- (stream-range 1 b)) + (let c^2 = (+ (* a a) (* b b))) + (let-values (c r) = (exact-integer-sqrt c^2)) + (stream:guard (zero? r)) + (stream (list a b c)))) |