(use-modules (srfi srfi-1) (srfi srfi-42)) (define (square x) (* x x)) ;; Euclid's formula. (define (generate-triple n m) (list (- (square n) (square m)) (* 2 n m) (+ (square n) (square m)))) (define (generate-triples max-n max-m) (concatenate (list-ec (:range n 2 max-n) (list-ec (:range m 1 (1- n)) (generate-triple n m))))) (define (find-triple-sum goal) (find (lambda (triple) (= (apply + triple) goal)) ;; Assumed that this range would be enough. :) (generate-triples 100 99))) (apply * (find-triple-sum 1000))