Created
November 5, 2019 10:46
-
-
Save vyzo/137dde3bfad5bfa8803ddc62f0940507 to your computer and use it in GitHub Desktop.
pythagorean triples with hand-written loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import :std/iter) | |
(export main) | |
(def (main) | |
(declare (fixnum) (not safe)) | |
(def i 1) | |
(let/cc break | |
(let lpz ((z 1)) | |
(let lpx ((x 1)) | |
(if (< x z) | |
(let lpy ((y x)) | |
(if (< y z) | |
(begin | |
(when (= (+ (* x x) (* y y)) (* z z)) | |
(displayln "(" x ", " y ", " z ")") | |
(if (< i 1000) | |
(set! i (1+ i)) | |
(break))) | |
(lpy (1+ y))) | |
(lpx (1+ x)))) | |
(lpz (1+ z))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment