Created
February 3, 2015 07:51
-
-
Save kremerben/a10e3c03d377fd2fed11 to your computer and use it in GitHub Desktop.
This file contains 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
# /* | |
# * Given two numbers, find all factors of each. | |
# * Return all of their common factors sorted from highest to lowest. | |
# * | |
# * Example 1: | |
# * Find all the common factors of 12 and 18. | |
# * Factors of 12 are 12, 6, 4, 3, 2, 1 | |
# * Factors of 18 are 18, 9, 6, 3, 2, 1 | |
# * The common factors of 12 and 18 are 6, 3, 2, 1 | |
# * | |
# * Example 2: | |
# * var common = commonFactors(20, 25); | |
# * console.log(common); // [5, 1] | |
# */ |
winnietong
commented
Feb 3, 2015
def common_factors(num1, num2):
common = []
for x in range(1, min(num1, num2)+1):
if num1 % x == 0 and num2 % x == 0:
common.insert(0,x)
return common
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment