Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. (A proper divisor of a number is a positive factor of that number other than the number itself. For example, the proper divisors of 6 are 1, 2, and 3.) 

For example, the smallest pair of amicable numbers is (220, 284); for the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110, of which the sum is 284; and the proper divisors of 284 are 1, 2, 4, 71 and 142, of which the sum is 220.

Derive function ```amicableNumbers(num1, num2)``` which returns ```true/True``` if pair ```num1 num2``` are amicable, ```false/False``` if not.

See more at https://en.wikipedia.org/wiki/Amicable_numbers

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def amicable_numbers(n1,n2):
	

Solutions:
def getDivs(n):
	return {1} | {y for x in range(2, int(n ** 0.5) + 1) for y in [n // x, x] if not n % x}

def amicable_numbers(n1, n2):
	return sum(getDivs(n1)) == n2 and sum(getDivs(n2)) == n1


def amicable_numbers(n1, n2):
	return spd(n1) == n2 and spd(n2) == n1

def spd(n):
	return sum((i for i in range(1, n) if n % i == 0))


def factors(num):
	return sum((i for i in range(1, num) if num % i == 0))

def amicable_numbers(n1, n2):
	return factors(n1) == n2 and factors(n2) == n1


def amicable_numbers(n1, n2):
	s1 = sum([x for x in range(1, n1) if n1 % x == 0])
	s2 = sum([x for x in range(1, n2) if n2 % x == 0])
	return s1 == n2 and s2 == n1


def amicable_numbers(n1, n2):
	divisors1 = [i for i in range(1, n1) if n1 % i == 0]
	divisors2 = [i for i in range(1, n2) if n2 % i == 0]
	return bool(sum(divisors1) == n2 and sum(divisors2) == n1)


sum_div = lambda n: sum((d + n // d for d in range(2, int(n ** 0.5) + 1) if not n % d)) + 1 - n ** 0.5 / 1 * (not n ** 0.5 % 1)
amicable_numbers = lambda x, y: sum_div(x) == y and sum_div(y) == x


def amicable_numbers(n1, n2):
	return sum((d for d in range(1, n1 // 2 + 1) if not n1 % d)) == n2 and sum((d for d in range(1, n2 // 2 + 1) if not n2 % d)) == n1


def amicable_numbers(n1, n2):
	divisor_sum = lambda x: sum((i for i in range(1, x) if x % i == 0))
	return divisor_sum(n1) == n2 and divisor_sum(n2) == n1


from functools import reduce

def amicable_numbers(n1, n2):
	s1 = reduce(lambda x, y: x + (y if n1 % y == 0 else 0), range(1, n1), 0)
	s2 = reduce(lambda x, y: x + (y if n2 % y == 0 else 0), range(1, n1), 0)
	return s1 == n2 and s2 == n1


def amicable_numbers(n1, n2):
	count_1 = 0
	count_2 = 0
	product = 0
	for i in range(1, n1):
		if n1 % i == 0:
			count_1 += i
	for i in range(1, n2):
		if n2 % i == 0:
			count_2 += i
	if n1 == count_2:
		product += 1
	if n2 == count_1:
		product += 1
	if product == 2:
		return True
	return False