Project Euler #13 understandning (Python)

python

Solution

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).

Problem

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) ```

Original source

Related problems