Guest User

Untitled

a guest
Mar 5th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class Integer
  2. def divis_by?(n)
  3. if n != 0
  4. self.to_f / n == (self.to_f / n).to_i
  5. end
  6. end
  7.  
  8. def factors
  9. f = [1]
  10. for i in 2..self-1
  11. f.push i if self.divis_by?(i)
  12. end
  13. f.push self
  14. f
  15. end
  16. end
  17.  
  18.  
  19.  
  20. i = 1
  21. add = 2
  22. while i.factors.length <= 500
  23. puts "#{i} #{i.factors.length}"
  24. i += add
  25. add += 1
  26. end
  27. puts "First triangle number with over 500 factors: #{i}"
Add Comment
Please, Sign In to add comment