Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. # Calculate all the primes between 0 and the value specified
  2. def primes(up_to)
  3. prev = []
  4. (2..up_to).select do |x|
  5. max_p = Math.sqrt(x).truncate
  6. if !prev.find { |y| y <= max_p ? x % y == 0 : break }
  7. prev << x
  8. end
  9. end
  10. end
Add Comment
Please, Sign In to add comment