Skip to content

Instantly share code, notes, and snippets.

/friendly.py
Created Dec 31, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.