Euler Problem 99

This was another easy one. Using natural logarithms, this routine runs very quickly (< 5 seconds). I also used the decimal class just in case I needed extra precision.

import psyco

import decimal
class Problem:
    def Solution(self):
        decimal.getcontext().prec = 50      
        P = []
        f = open("base_exp.txt", "r")
        for row in f.readlines():
            newRow = []
            for column in row.split(","):
        max = 0
        pos = 0
        for pair in P:
            v = decimal.Decimal(pair[1]*decimal.Decimal(pair[0]).ln()).exp()
            if v > max:
                max = v
                pos = P.index(pair)+1
            print P.index(pair)+1,
        return "\nAnswer = " + str(pos)
if __name__ == '__main__':
    P = Problem()
    print P.Solution()

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s