Created
March 7, 2014 10:11
-
-
Save wazery/9408934 to your computer and use it in GitHub Desktop.
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
#! /usr/bin/ruby | |
def prime? n | |
(2..(n-1)).each { |x| return false if n % x == 0 } | |
true | |
end | |
def euler_3(n) | |
i = 2 | |
numbers = [] | |
sum = 1 | |
while sum < n | |
if n % i == 0 && prime?(i) | |
numbers << i | |
sum *= i | |
end | |
i += 1 | |
end | |
puts "The answer is #{numbers.last}" | |
end | |
n = ARGV[0].to_i | |
euler_3 n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment