Created
November 14, 2011 06:20
-
-
Save hyfather/1363373 to your computer and use it in GitHub Desktop.
My solution to problem #3 on projecteuler.net
This file contains hidden or 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 factorize(list, num, p) | |
while true | |
list.each_with_index { |e, i| list[i] = 0 if e!=p && e%p == 0 } | |
list.each{|e| p = e and break if e > p} | |
if num % p == 0 | |
# p num | |
return factorize(list[p..Math.sqrt(num/=p)], num, p) | |
end | |
return num if list.empty? | |
end | |
end | |
big = 600851475143 | |
big_list = (2..Math.sqrt(big)).to_a | |
p factorize(big_list, big, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment