Created
October 8, 2009 03:10
-
-
Save eric1234/204674 to your computer and use it in GitHub Desktop.
Problem 7 on Project Euler
This file contains hidden or 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
| class Numeric | |
| def divisible_by? num | |
| self % num == 0 | |
| end | |
| def prime? | |
| not (2..self.sqrt.floor).any? {|i| self.divisible_by? i} | |
| end | |
| def sqrt | |
| Math.sqrt self | |
| end | |
| end | |
| primes = [2, 3] | |
| until primes.size == 10001 | |
| i = primes.last + 2 | |
| i += 2 until i.prime? | |
| primes << i | |
| end | |
| puts primes.last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment