Skip to content

Instantly share code, notes, and snippets.

@danielkcz
Created August 4, 2014 14:35
Show Gist options
  • Select an option

  • Save danielkcz/df0aa5c3d95479ed8745 to your computer and use it in GitHub Desktop.

Select an option

Save danielkcz/df0aa5c3d95479ed8745 to your computer and use it in GitHub Desktop.
Getting prime numbers
primes = []
findNextPrime = ->
len = primes.length
pr = primes[len - 1] or 1
loop
pr += if len > 2 then 2 else 1
divides = false
i = 0
# discard the number if it divides by one earlier prime.
while i < len
if (pr % primes[i]) is 0
divides = true
break
i++
break unless divides is true
primes.push pr
return pr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment