Update…

Lots of stuff happening in the past week. Let me begin with that news which should come as a blow to storage enthusiasts. The HD-DVD format is going forever. Toshiba says it will no longer create HD-DVD players/records. Now, I liked the HD-DVD format for its ECMAScript support. Well thats over. Then the US blew up a satellite, China’s pissed and wants to know more about the mission, my board exams are getting closer ( bleagh! ). Anyway, here is an update on my “work” in the past week.

Oh BTW, while solving a question related to the Fibonacci sequence, I found a supercool formula - the Binet’s formula. Let the greatest integer function be represented by “[]”

f(x) = [x]

let F represent the Fibonacci sequence. The Binet’s formula states that

F(n) = [{(1 + sqrt(5))^n}-{(1-sqrt(5))^n} / (2^n * sqrt(5))]

There ! Now you can solve that Fibonacci problem in the project euler archives.

I solved another sum. Here is the question:

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ? b, then a and b are an amicable pair and each of a and b are called amicable numbers.For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. Evaluate the sum of all the amicable numbers under 10000.

Here is the solution:

#!/usr/bin/env python
#Amicable numbers

def makeFactors(number):
        factor_list = []
        if number % 2 == 0:
                for i in range(1, number / 2 + 1):
                        if number % i == 0:
                                factor_list.append(i)
                        else:
                                continue
        else:
                for i in range(1, (number + 1)/2):
                        if number % i == 0:
                                factor_list.append(i)
                        else:
                                continue
        return factor_list

def checkAmicable(number):
        factor_list = makeFactors(number)
        factor_sum = sum(factor_list)
        new_factor_list = makeFactors(factor_sum)
        new_factor_sum = sum(new_factor_list)
        if new_factor_sum == number and factor_sum != number:
                return True
        else:
                return False

amicable_list = []
for number in range(0, 10001):
        if checkAmicable(number):
                amicable_list.append(number)
        else:
                continue

print sum(amicable_list)

Thats it for now, goodbye !

1 comment so far ↓

#1 Mgccl on 03.16.08 at 5:53 am

You might want to use latex to render the math equations, that will be much easier to read.

Leave a Comment