2017-06-10

Project Euler Problem 8

In the last post I wrote about finding a feature for measuring the run time for an algorithm. It seems as though I either need to install plugins for PyCharm or I need to upgrade to a commercial version of it. I'll leave it for now.

Now it's time for problem 8:


What I'm going to do is to cut out 13 digits from the number, multiply them, save the product, and then doing the same thing after shifting the 13 digits one to the right. Instead of saving every product, I'll compare the new one and the current one and only save the larger one.


From now on, I'll stop posting the problems here on the blog and let you read the problem yourself on ProjectEuler.net instead.

The code I used for this problem is:

fullNumber = '731671765313306249192....' # insert numbers hereproduct = 1newProduct = 1
for x in range(0, 987):
    for y in range(x, x+13):
        newProduct *= int(fullNumber[y])
    if newProduct > product:
        product = newProduct
    newProduct = 1
print("product: ", product)

No comments:

Post a Comment