euler/euler012.rb

31 lines
431 B
Ruby
Raw Normal View History

2014-04-25 23:59:14 +00:00
class Integer
def divisors
divisors = []
(1..Math.sqrt(self).to_i).each do |num|
if self % num == 0
divisors << num
divisors << self / num
end
end
divisors
end
end
triangle = Enumerator.new do |y|
sum = 1
next_num = 2
loop do
y << sum
sum += next_num
next_num += 1
end
end
val = triangle.next
while val.divisors.count < 500
val = triangle.next
end
puts val