Created
January 11, 2019 10:05
-
-
Save sashaegorov/255134cf4a57faa462aa6845c04310e2 to your computer and use it in GitHub Desktop.
Prime numbers with Ruby endless range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
factors = -> (n) { (1..n).select{|x| n % x === 0} } | |
prime = ->(n){ (factors === n) === [1,n] } | |
(1..).lazy.select(&prime).take(10).to_a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment