-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path003.rb
45 lines (35 loc) · 859 Bytes
/
003.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/ruby
#BTW, this shit takes forever to run, my factorization is balls slow :(
number = 600851475143
factors = Array.new
i = 1
while i <= number/2 # no factor of a number will be greater than half of the number... there's some additional juju to extend that statement to be a bit more useful, but I haven't the sauce at the moment
if number%i == 0
# puts i," is a factor of ",number
factors << i
# else
# puts i," is not a factor of ",number
end
i += 1
end
#puts factors
integers = Array.new
j = 2
while j < number/2
integers << j
j += 1
end
primes = integers
prime_index = 0
p = integers[prime_index]
until integers[prime_index]**2 > integers[-1]
p = integers[prime_index]
primes.each{|x|
if x != p && x%p == 0
primes.delete(x)
end
}
prime_index += 1
end
answer = primes | factors
puts "The answer is: ",answer[-1]