Skip to content

Instantly share code, notes, and snippets.

@christianjuth
Last active May 7, 2016 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianjuth/99df939724dec6174de1f5081d00abb5 to your computer and use it in GitHub Desktop.
Save christianjuth/99df939724dec6174de1f5081d00abb5 to your computer and use it in GitHub Desktop.
# global vars
perfect_number = []
stop = 100 # will find up to this many perfect numbers
# (probably will crap out at about four
# perfect nubmers due to size of equation)
i = 0
until perfect_number.size >= stop
# set vars
i = i + 1
# get multiplus
$multipuls = []
i.times do |x|
if x > 0 && i % x == 0
$multipuls.push(x)
end
end
# add up multipuls
$sum = 0
for $num in $multipuls
$sum = $sum + $num
end
# check if number is perfect
if i == $sum
perfect_number.push(i)
puts "got one #{stop - perfect_number.size} left"
puts perfect_number.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment