Last active
May 7, 2016 01:50
-
-
Save christianjuth/99df939724dec6174de1f5081d00abb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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