Last active
August 29, 2015 13:57
-
-
Save negamorgan/9412725 to your computer and use it in GitHub Desktop.
Largest Prime
This file contains 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
# Euler problem 3 | |
# used my old prime method from school week 1 | |
class LargestPrime | |
def largest(number) | |
Math.sqrt(number).to_i.downto(2) do |i| | |
# prime factor is a prime number that divides the integer exactly | |
return i if number % i == 0 && prime?(i) | |
end | |
end | |
def prime?(number) | |
(2..Math.sqrt(number)).each { |i| return false if number % i == 0} | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment