Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. def check_abundant(x)
  2. total(x) > x
  3. end
  4.  
  5. def total (x)
  6. sum = 1
  7.  
  8. (2..Math.sqrt(x)).each do |i|
  9. sum = sum + x + x/i if x%i == 0 && i != Math.sqrt(x)
  10. end
  11. sum
  12. end
  13.  
  14. def non_abundant_sums
  15. abundant_arr = []
  16. s = 0
  17. (12..28123).each do |x|
  18. if check_abundant(x)
  19. abundant_arr << x
  20. end
  21. end
  22.  
  23. (1..28123).each do |x|
  24. s = s + x unless abundant_arr.include? (total(x) - x)
  25. end
  26. s
  27. end
  28.  
  29. puts non_abundant_sums
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement