Skip to content

Instantly share code, notes, and snippets.

@NalaGinrut
Last active December 23, 2015 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NalaGinrut/6710088 to your computer and use it in GitHub Desktop.
Save NalaGinrut/6710088 to your computer and use it in GitHub Desktop.
求from到to之间所有勾股数
(use-modules (srfi srfi-1) (ice-9 control))
(define (either . args) (shift k (for-each k args)))
(define (sq x) (* x x))
(define (choice from to)
(reset (let ((ll (iota to from)))
(let ((x (apply either ll))(y (apply either ll))(z (apply either ll)))
(if (= (sq z) (+ (sq x) (sq y)))
(format #t "~a^2 + ~a^2 = ~a^2~%" x y z))))))
@NalaGinrut
Copy link
Author

(choice 1 5)
==>
3^2 + 4^2 = 5^2
4^2 + 3^2 = 5^2

try 1~100 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment