Use none? rather than not empty?
[project-euler.git] / euler12.rb
1 load 'divisors.rb'
2
3 require 'logger'
4 $log = Logger.new(STDERR)
5 $log.level = Logger::WARN
6
7
8 # The nth triangle number
9 def triangle(n)
10 n * (n + 1) / 2
11 end
12
13 def first_triangle_number_with_more_than_n_divisors(n)
14 i = 1
15 while triangle(i).number_of_divisors <= 500
16 $log.info { "Triangle number #{i} is #{triangle(i)}, which has #{triangle(i).number_of_divisors} divisors" }
17 i += 1
18 end
19 $log.info { "Triangle number #{i} is #{triangle(i)}, which has #{triangle(i).number_of_divisors} divisors" }
20 triangle i
21 end
22
23 if __FILE__==$0
24 puts first_triangle_number_with_more_than_n_divisors(500)
25 end