Skip to content

Instantly share code, notes, and snippets.

@vyzo
Created November 5, 2019 11:09
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/e113490c22d1b7b6cd71d49dc7869a69 to your computer and use it in GitHub Desktop.
Save vyzo/e113490c22d1b7b6cd71d49dc7869a69 to your computer and use it in GitHub Desktop.
pythagorean triples with for loops and explicit step
(import :std/iter)
(export main)
(def (main)
(declare (fixnum) (not safe))
(def i 1)
(let/cc break
(for* ((z (in-naturals 1))
(x (in-range 1 z 1))
(y (in-range x z 1)))
(when (= (+ (* x x) (* y y)) (* z z))
(displayln "(" x ", " y ", " z ")")
(if (< i 1000)
(set! i (1+ i))
(break))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment