day1/exercise/amicable_debug.py
author Prabhu Ramachandran <prabhu@aero.iitb.ac.in>
Mon, 28 Jun 2010 00:14:02 -0500
branchscipy2010
changeset 426 7d8738ce004d
parent 380 669b72283b55
permissions -rw-r--r--
Adding an acknowledgement slide to session 1. Minor changes to session 2.

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.