Skip to content

Instantly share code, notes, and snippets.

@viveksyngh
Created August 1, 2015 15:40
Show Gist options
  • Save viveksyngh/2b850df23790497571b9 to your computer and use it in GitHub Desktop.
Save viveksyngh/2b850df23790497571b9 to your computer and use it in GitHub Desktop.
Finds all the factors of an integer
__author__ = 'Vivek'
#This function returns all the factors of an integer in sorted order
def allFactors(A):
"""
:param: A positive integer
:return: All the factors of the integer in sorted order.
"""
res = []
firstHalf = []
secondHalf = []
for i in range(1, int(A ** 0.5) + 1) :
if A%i == 0 :
firstHalf.append(i)
if i != A ** 0.5 :
secondHalf.insert(0, A/i)
firstHalf.extend(secondHalf)
return firstHalf
print(allFactors(36))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment