Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Calculate all the primes between 0 and the value specified
- def primes(up_to)
- prev = []
- (2..up_to).select do |x|
- max_p = Math.sqrt(x).truncate
- if !prev.find { |y| y <= max_p ? x % y == 0 : break }
- prev << x
- end
- end
- end
Add Comment
Please, Sign In to add comment