Skip to content

Instantly share code, notes, and snippets.

@charlesponti
Created May 7, 2013 16:58
Show Gist options
  • Save charlesponti/5534234 to your computer and use it in GitHub Desktop.
Save charlesponti/5534234 to your computer and use it in GitHub Desktop.
Project Euler: Problem 3
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