Skip to content

Instantly share code, notes, and snippets.

@daniel-g
Created January 7, 2014 18:37
Show Gist options
  • Save daniel-g/8304242 to your computer and use it in GitHub Desktop.
Save daniel-g/8304242 to your computer and use it in GitHub Desktop.
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