Skip to content

Instantly share code, notes, and snippets.

@dnase
Created March 20, 2013 12:51
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 dnase/5204397 to your computer and use it in GitHub Desktop.
Save dnase/5204397 to your computer and use it in GitHub Desktop.
class Integer
def is_prime?
return false if self <= 1
2.upto(Math.sqrt(self).to_i) { |x| return false if self % x == 0 }
true
end
end
Math.sqrt(600851475143).to_i.downto(2) { |n| puts n if n.is_prime? && 600851475143 % n == 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment