Skip to content

Instantly share code, notes, and snippets.

@wazery
Created March 7, 2014 10:11
Show Gist options
  • Save wazery/9408934 to your computer and use it in GitHub Desktop.
Save wazery/9408934 to your computer and use it in GitHub Desktop.
#! /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