Skip to content

Instantly share code, notes, and snippets.

@vyzo
Created November 5, 2019 10:46
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 vyzo/137dde3bfad5bfa8803ddc62f0940507 to your computer and use it in GitHub Desktop.
Save vyzo/137dde3bfad5bfa8803ddc62f0940507 to your computer and use it in GitHub Desktop.
pythagorean triples with hand-written loops
(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