Skip to content

Instantly share code, notes, and snippets.

@mrded
Created November 20, 2013 21:09
Show Gist options
  • Save mrded/7571086 to your computer and use it in GitHub Desktop.
Save mrded/7571086 to your computer and use it in GitHub Desktop.
Ruby: Get array of prime numbers.
(1..100).select {|x| (1..x).select{|y|x%y==0}.size==2 }
=> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment