Skip to content

Instantly share code, notes, and snippets.

@magical
Created March 22, 2018 18:16
Show Gist options
  • Save magical/a16a2b795e078dd86330f815fe508150 to your computer and use it in GitHub Desktop.
Save magical/a16a2b795e078dd86330f815fe508150 to your computer and use it in GitHub Desktop.
prime sieve
#!/usr/bin/env hy
(def N 999)
(def a (+ [1 1] (* [0] N)))
(let [(i 1) (j 0)]
(while (< i N)
(if (= i j) (print i))
(cond
[(> j N) (setv j 0)]
[(>= j i) (do (setv (get a j) 1)
(setv j (+ j i)))]
[(get a i) (setv i (inc i))]
[true (setv j i)])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment