RosettaCodeData/Task/Primality-by-trial-division/CoffeeScript/primality-by-trial-division.coffee
2013-04-11 11:14:19 -07:00

12 lines
261 B
CoffeeScript

is_prime = (n) ->
# simple prime detection using trial division, works
# for all integers
return false if n <= 1 # by definition
p = 2
while p * p <= n
return false if n % p == 0
p += 1
true
for i in [-1..100]
console.log i if is_prime i