summaryrefslogtreecommitdiff
path: root/day1/exercise/amicable_debug.py
diff options
context:
space:
mode:
authorSantosh G. Vattam2010-03-11 18:01:23 +0530
committerSantosh G. Vattam2010-03-11 18:01:23 +0530
commite165b2bf43110b3faf24af89fa479afcac6dad25 (patch)
tree671a499f31425f35ea158136da94f7a5272749d8 /day1/exercise/amicable_debug.py
parentb12e0358be2b89b5b0545c72977c1c25b4daa8a9 (diff)
downloadworkshops-e165b2bf43110b3faf24af89fa479afcac6dad25.tar.gz
workshops-e165b2bf43110b3faf24af89fa479afcac6dad25.tar.bz2
workshops-e165b2bf43110b3faf24af89fa479afcac6dad25.zip
Updated after Day 2 at GRDCS
Diffstat (limited to 'day1/exercise/amicable_debug.py')
-rw-r--r--day1/exercise/amicable_debug.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/day1/exercise/amicable_debug.py b/day1/exercise/amicable_debug.py
index 9369219..6f42d86 100644
--- a/day1/exercise/amicable_debug.py
+++ b/day1/exercise/amicable_debug.py
@@ -1,16 +1,20 @@
import math
def aliquot(n):
- sum = 0
- for i in range(1, math.sqrt(n)+1):
+ sum = 1
+ i = 2
+
+ while i * i < n:
if n % i == 0:
- sum += i + n/i
+ sum += i + (n / i)
+ i += 1
+ if i*i == n: sum += i
return sum
amicable = []
-for n in range(10000, 100000):
+for n in range(1000, 10000):
m = aliquot(n)
- if aliquot(m) == n:
+ if m > n and aliquot(m) == n:
amicable.append((m, n))
print amicable