Created
January 7, 2014 18:37
-
-
Save daniel-g/8304242 to your computer and use it in GitHub Desktop.
This file contains 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
require 'prime' | |
def divisors_count(n) | |
Prime.prime_division(n).reduce(1) do |mem, prime_factor| | |
mem * (prime_factor[1] + 1) | |
end | |
end | |
def triangle_number(n) | |
(n)*(n+1)/2 | |
end | |
i = 1 | |
divs = 0 | |
last_tn = 0 | |
while divs < 500 do | |
i += 1 | |
last_tn = triangle_number(i) | |
divs = divisors_count(last_tn) | |
end | |
puts last_tn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment