     (17 votes, average: 5.00 out of 5) Loading...

## Project Euler 16 Solution ## Project Euler 16: Sum of the digits in the number 2^1000

#### Project Euler 16: Project Euler 16 Problem Description

Project Euler 16: 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 21000?

#### Analysis

We are asked to calculate a very large power of 2 and sum the individual digits of the result. As Python natively supports arbitrary precision integers, with millions of digits if necessary, it makes this task easy to do.

We calculate 21000 and convert the result to a string: `sum(map(int, str(pow(2, 1000))))`. Next, using the `map` function with the result string at the iterator and `int` as the application function we split the digits of the result into individual characters and convert to integers: `sum(map(int, str(pow(2, 1000))))`. The sum of the digits is calculated by the `sum` function as the answer to the problem: `sum(map(int, str(pow(2, 1000))))`.

The HackerRank Project Euler 16 version increases the exponent to 10,000 and runs a hundred trials in a few milliseconds. Same solution. This program and method
solves all test cases for
Project Euler 16 on HackerRank

#### Project Euler 16 Solution

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

#### Afterthoughts

Project Euler 16 Solution last updated