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

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.

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

#### Answer

Slowly swipe from either end beginning with the white vertical bar to get an idea of the starting or ending digits. For less drama, just double click the answer area. The distance between the two bars will give you an idea of the magnitude. Touch devices can tap and hold the center of the box between the two bars and choose*define*to reveal the answer.

#### 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,

your friend,

Mike

June 8, 2014

*Project Euler 13 Solution last updated*

Hey, I was wondering how you saved the file? I’m running the same code off repl python and nothing seems to run

Trinket allows an easy way to create tabs with programs text or data text. You can see the two tabs next to one another at the top of the trinket window.

Also, check out this repl: https://repl.it/NWgU/1