Skip to content

Instantly share code, notes, and snippets.

@yuuki
Created August 12, 2012 08:40
Show Gist options
  • Select an option

  • Save yuuki/3330697 to your computer and use it in GitHub Desktop.

Select an option

Save yuuki/3330697 to your computer and use it in GitHub Desktop.
def d(n)
t = (2..Math.sqrt(n).floor).select{|i| n % i == 0}
([1] + t + t.map{|i| n/i}).inject(:+)
end
amicable_num = (2...10000).select do |a|
b = d(a)
a == d(b) and a != b
end
puts amicable_num.inject(:+)
# 31626
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment