Created
December 31, 2012 00:08
-
-
Save anonymous/4416237 to your computer and use it in GitHub Desktop.
Find friendly numbers, based on a comment by dannycalifornia45 to this video http://youtu.be/fUSZBVYZdKY
This file contains hidden or 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
def friendly_numbers(limit): | |
n=0 | |
i=0 | |
while i<limit: | |
n+=1 | |
friendly=[] | |
for j in range(1,n): | |
if n%j==0: | |
friendly.append(j) | |
friend=sum(friendly) | |
friendlier=[] | |
for k in range(1, friend): | |
if friend%k==0: | |
friendlier.append(k) | |
friendliest=sum(friendlier) | |
if n==friendliest and n!=friend: | |
print n, "and", friend, "are besties!" | |
i+=1 | |
friendly_numbers(285) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment