Skip to content

Instantly share code, notes, and snippets.

@vfrico
Created December 6, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfrico/58e75f099f7bec6da470336b82b6d9bb to your computer and use it in GitHub Desktop.
Save vfrico/58e75f099f7bec6da470336b82b6d9bb to your computer and use it in GitHub Desktop.
Obtiene los divisores de un número (Versión recursiva)
#!/usr/bin/python3
def divisor_helper(n, i):
if i == 0:
return []
elif n % i == 0:
recursion = [i] + divisor_helper(n, i-1)
return recursion
else:
return divisor_helper(n, i-1)
def divisores(n):
if n == 0:
return [0]
elif n == 1:
return [1]
else:
return divisor_helper(n, n)
print(divisores(12))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment