(21 votes, average: 5.00 out of 5)

## Project Euler 13: Find the first ten digits of the sum of one-hundred 50-digit numbers.

#### Project Euler 13 Problem Description

Project Euler 13: Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.

37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
… {data continues}

#### Analysis

This problem requires us to find the first 10 (leftmost) digits of the sum of one hundred 50-digit integers.

The numbers were saved to a file named pe13.txt (second Trinket tab next to the main.py tab). This keeps the data and the program separate and the process easy to comprehend.

The file is read as strings and converted to a list of integers using the `map` function with `open` as the iterator and `int` as the application function: `sum(map(int, open('pe13.txt')))`. After the end of the file is reached the list is fed to the `sum` function which adds the integers together: `sum(map(int, open('pe13.txt')))`. This integer sum is finally converted to a string str(total)[:10] and truncated to the top 10 digits for a solution: str(total)[:10].

HackerRank increases the data set from 100 to 1000 numbers. Same solution.

This program and method
solves all test cases for
Project Euler 13 on HackerRank

#### Project Euler 13 Solution

Runs < 0.001 seconds in Python 2.7.
Use this link to get the Project Euler 13 Solution Python 2.7 source.

#### Afterthoughts

• Also in one line: `print "Top 10 digits of sum =", str(sum(map(int, open('pe13.txt'))))[:10]`

We had to copy and paste the data from the problem description and save it to a file. Yeah, I know I already mentioned that, but I just need more content so I can get this paged indexed. Anyway, how is everything? Hope you’re doing well and I’m glad you stopped by. Oh, don’t worry, only 30 people in the last 5 years have ever ventured to this page, so our conversation is, more than likely, quite personal and mostly private.

Have a great day – and check out some of my other pages.

Thanks,