aboutsummaryrefslogtreecommitdiff
path: root/examples/pythagorean-triples.scm
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2024-06-16 18:39:20 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2024-06-16 18:39:34 +0900
commit6f4601d5bd245e99831cedb12b732d77501a16e1 (patch)
tree9942598a0e2103426fab1d77f3cdbdf2d0039fe8 /examples/pythagorean-triples.scm
parent58f89e40b2851d334f239d629bbe28cf59f94876 (diff)
Add usages section to README.md
Diffstat (limited to 'examples/pythagorean-triples.scm')
-rw-r--r--examples/pythagorean-triples.scm11
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))))