Skip to content

Instantly share code, notes, and snippets.

@denlab
Created September 21, 2011 12:18
Show Gist options
  • Save denlab/1231894 to your computer and use it in GitHub Desktop.
Save denlab/1231894 to your computer and use it in GitHub Desktop.
coding-dojo-20110921
(defn primes [n] nil
(reverse
(loop [candidate 2 current n acc []]
(if (zero? current)
acc
(if (every? #(not= 0 (rem candidate %)) acc)
(recur (inc candidate) (dec current) (cons candidate acc))
(recur (inc candidate) current acc))))))
(fact
(primes 1) => [2]
(primes 2) => [2 3]
(primes 3) => [2 3 5])
@cgrand
Copy link

cgrand commented Sep 23, 2011

Menfin le décompte des objets intermédiaires quand on utilise un algo naïf c'est pas important. Là on est dans une approche parnassienne du code. https://gist.github.com/1236838#comments

"Le code pour le code."

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