I'm having problems with Project Euler . One of the questions:
The main factors of 13195 are 5, 7, 13 and 29. What is the maximum prime coefficient of the number 600851475143?
I have code written ... and it works:
class Integer
def primeFactors
load('/home/arseno/ruby/lib/prime.rb')
a = []
for i in (1..self)
div = self.to_f/i.to_f
if((div==div.to_i)&&(Prime.prime?(i)))
a << i
end
end
a
end
end
puts 13195.primeFactors
Outputs:
5
7
13
29
So far so good! Now, when I put in 600851475143 instead, my terminal freezes (by right, it calculates a lot of everything!) So what I tried to do was put puts iinside the / if loop so that I capture the output when it repeats through ... in mode real time.
But by putting this puts iin a loop, Ruby does not output the variable during the iteration; instead, it holds the values ββin some kind of buffer and flushes them when the calculation is complete.
Ruby ( 10 ), , .
Ruby ( ?) ? , ? ?