Created
May 7, 2013 16:58
-
-
Save charlesponti/5534234 to your computer and use it in GitHub Desktop.
Project Euler: Problem 3
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
def is_prime?(num) | |
2.upto(num-1) { |i| return false if ((num % i) == 0) } | |
true | |
end | |
def largest_prime(num) | |
primes = [] | |
1.upto(num) { |i| primes << i if num % i == 0 && is_prime?(i) } | |
p primes.last | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment