RosettaCodeData/Task/Primality-by-trial-division/CoffeeScript/primality-by-trial-division.coffee

13 lines
261 B
CoffeeScript
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
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