Skip to content

Instantly share code, notes, and snippets.

@sashaegorov
Created January 11, 2019 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sashaegorov/255134cf4a57faa462aa6845c04310e2 to your computer and use it in GitHub Desktop.
Save sashaegorov/255134cf4a57faa462aa6845c04310e2 to your computer and use it in GitHub Desktop.
Prime numbers with Ruby endless range
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