summaryrefslogtreecommitdiff
path: root/day1/exercise/amicable_debug.py
blob: 6f42d863dcee4795595ed4740f5ef576de0dfe09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import math

def aliquot(n):
    sum = 1
    i = 2

    while i * i < n: 
        if n % i == 0:
            sum += i + (n / i)
        i += 1
    if i*i == n: sum += i
    return sum

amicable = []
for n in range(1000, 10000):
    m = aliquot(n)
    if m > n and aliquot(m) == n:
        amicable.append((m, n))

print amicable

# please please please profile this.