Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project Euler #13 understandning (Python)

Tags:

python

Problem 13: http://projecteuler.net/problem=13

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. So, is the question sum the 5000 digits and the answer is the first 10 digits in the result?

bignumber = list of the 5000 digits
sum(bignumber) = abcdefghijklmnopqrst...    
answer = abcdefghj

Well when I do this sum(bignumber) = 22660 (which even is not 10 digits)...

have I misread the question?

def foo():
    with open ("bignumber", "r") as myfile:
        data=myfile.read().replace('\n', '')
    data = map(long, data)
    datasum = sum(data)
    return (datasum)
like image 940
Isbister Avatar asked Oct 03 '22 08:10

Isbister


1 Answers

You are misreading the question.

They give you 100 numbers that you need to sum, each of which is 50 digits long (aka magnitude of X*10^50). The 50 digit part is there so you cant just use traditional int/long data types (As JLLAgrange points out, this part shouldn't be a problem for python since integers have no max value).

like image 120
Colin D Avatar answered Oct 21 '22 14:10

Colin D