Skip to content

Instantly share code, notes, and snippets.

Created December 31, 2012 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4416237 to your computer and use it in GitHub Desktop.
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
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