Created
September 21, 2011 18:22
-
-
Save ardumont/1232874 to your computer and use it in GitHub Desktop.
Return the list of the n first prime numbers
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
(ns dojo-coding-0.core | |
(:use [clojure.test :only [run-tests]]) | |
(:use [midje.sweet]) | |
(:use [clojure.contrib.repl-utils :only [show]]) | |
(:use [clojure.pprint :only [pprint]]) | |
(:use [clojure.walk :only [macroexpand-all]])) | |
(defn prime-numbers "Return the list of the n first prime numbers" | |
[n] | |
(loop [candidate 2 current n primes []] | |
(if (zero? current) | |
primes | |
(if (every? #(not= 0 (rem candidate %)) primes) | |
(recur (inc candidate) (dec current) (conj primes candidate)) | |
(recur (inc candidate) current primes) | |
))) | |
) | |
; list of the n primes number | |
(fact (prime-numbers 0) => '()) | |
(fact (prime-numbers 1) => '(2)) | |
(fact (prime-numbers 2) => '(2 3)) | |
(fact (prime-numbers 3) => '(2 3 5)) | |
(fact (prime-numbers 4) => '(2 3 5 7)) | |
;.;. Good code is its own best documentation. -- Steve McConnell | |
(fact (prime-numbers 100) => '(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541)) |
le mien j'avais deja choisi clojure mais je sais pas si ca se voit
2011/9/21 denlab <
[email protected]>
… set the langage to "clojure" so have color highlighting :)
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1232874
tu te moques !! https://gist.github.com/1233281
non!
J'ai pas compris.
Je crois que je suis fatigue :D
2011/9/21 denlab <
[email protected]>
… tu te moques !! https://gist.github.com/1233281
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1232874
Au moment ou j'ai cree le gist, j'ai vu qu'on pouvait choisir la langue et j'ai pris clojure.
ok, ca ne l'a pas fait parce qu'il fallait que je donne l'extension .clj au fichier.
j'c'rois pas
donner le langage suffi il me semb'
2011/9/21 Antoine Romain Dumont <
[email protected]>
… ok, ca ne l'a pas fait parce qu'il fallait que je donne l'extension .clj au
fichier.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1232874
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
set the langage to "clojure" so have color highlighting :)