Solution to the 16th Project Euler Problem - Power Digit Sum - in Javascript.

The 16th Project Euler problem - Power Digit Sum - is stated as follows. 2^{15} = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^{1000}?

```
function addIntegerArrays(a = [], b = [], memo = '', carry = 0) {
if (a.length + b.length + carry === 0) {
return memo
}
// Get current number from the end of both
const currentNumberA = a[a.length - 1] || 0;
const currentNumberB = b[b.length - 1] || 0;
// Sum the carry and the last digits or default to 0
const sum = carry + currentNumberA + currentNumberB;
const nextNumber = sum % 10;
const nextCarry = sum > 9 ? 1 : 0;
const nextA = a.slice(0, a.length - 1);
const nextB = b.slice(0, b.length - 1);
const result = `${nextNumber}${memo}`;
return addIntegerArrays(nextA, nextB, result, nextCarry);
}
function addStrings(a, b) {
// Convert strings to arrays.
const preparedA = a.split('')
.map(v => parseInt(v, 10));
const preparedB = b.split('')
.map(v => parseInt(v, 10));
return addIntegerArrays(preparedA, preparedB);
}
// Create a range of length N - 1.
const result = new Array(1000 - 1).fill(0)
// Starting at 2, hence N-1, double the value for every step.
.reduce(memo => addStrings(memo, memo), "2")
// Split the result into single chars.
.split('')
// Convert the chars to integers.
.map(str => parseInt(str))
// Sum the integers.
.reduce((memo, item) => memo + item);
```

- [project-euler] Project Euler Problem 17 - Number Letter Counts - solved with R
- [project-euler] Project Euler Problem 16 - Power Digit Sum - solved with Javascript
- [project-euler] Project Euler Problem 15 - Lattice Paths - solved with R
- [project-euler] Finding the 10001st prime with R
- [project-euler] Find longest Collatz sequence using Javascript
- [project-euler] Sum large numbers with Kotlin versus Javascript
- [tech-test] What is a binary tree and how to invert it using Kotlin
- [project-euler] Find Highly Divisible Triangular Numbers with Kotlin
- [project-euler] Find the Largest Product in a Grid with Rust
- [project-euler] Summation of the First Two Million Primes with Rust
- [project-euler] Finding the largest product in a series with Rust
- [project-euler] Finding the 10001st prime with Rust
- [js] The complete list of rational numbers with Stern-Brocot and Javascript
- [project-euler] Project Euler number six solved with Rust
- [project-euler] Smallest positive number that is evenly divisible by all of the numbers from 1 to 20 with Rust
- [project-euler] Finding the largest palindrome product with Rust
- [project-euler] Get the largest prime factor with Reason
- [project-euler] Find the sum of all even Fibonacci numbers below four million with OCaml
- [project-euler] Finding the sum of all multiples of 3 or 5 below 1000 with OCaml
- [project-euler] Special Pythagorean Triplet solved with Reason
- [personal] New Year's Resolution 2018