aboutsummaryrefslogtreecommitdiff
path: root/examples/pythagorean-triples.scm
blob: 4f620afb6aad37960ab402424a66d98756601fee (about) (plain)
1
2
3
4
5
6
7
8
9
10
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))))