feat(euler): 16 - Power digit sum

-
This commit is contained in:
newt 2024-10-09 18:02:40 +01:00
parent be39d481e7
commit 867aa5a6fd
2 changed files with 16 additions and 1 deletions

View file

@ -27,7 +27,7 @@ The source code can be found in the [src](src) directory. My thoughts about some
- [x] [14 - Longest Collatz sequence](src/14%20-%20Longest%20Collatz%20sequence.ts)
- [x] [15 - Lattice paths](src/15%20-%20Lattice%20paths.ts)
- [Thoughts](thoughts/15%20-%20Lattice%20paths.md)
- [ ] 16 - Power digit sum
- [x] [16 - Power digit sum](src/16%20-%20Power%20digit%20sum.ts)
- [ ] 17 - Number letter counts
- [ ] 18 - Maximum path sum I
- [ ] 19 - Counting Sundays

View file

@ -0,0 +1,15 @@
export {};
const powerDigitSum = (base: number, power: number) => {
const answer = BigInt(base ** power).toString();
let sum = 0;
for (let i = 0; i < answer.length; i++) {
const number = parseInt(answer[i]);
sum += number;
}
return sum;
};
console.log(powerDigitSum(2, 1000));