Skip to content

Instantly share code, notes, and snippets.

@leeacto
Created July 1, 2013 01:24
Show Gist options
  • Select an option

  • Save leeacto/5897802 to your computer and use it in GitHub Desktop.

Select an option

Save leeacto/5897802 to your computer and use it in GitHub Desktop.
def d(num)
arr = (1..(num/2)).to_a.keep_if { |i| num % i == 0}
arr = [1] if num == 1
arr.inject(:+)
end
st = Time.new
amic = []
for i in 1...7500
if i*2 < d(i*2) && i*2 == d(d(i*2))
amic << i*2
amic << d(i*2)
puts "#{i*2} - #{d(i*2)}"
i -= ((i*2) % 1000)/2
i += 499
puts i
end
end
puts amic.inject(:+)
en = Time.new - st
puts en
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment