Skip to content

Instantly share code, notes, and snippets.

@eric1234
Created October 8, 2009 03:10
Show Gist options
  • Select an option

  • Save eric1234/204674 to your computer and use it in GitHub Desktop.

Select an option

Save eric1234/204674 to your computer and use it in GitHub Desktop.
Problem 7 on Project Euler
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