-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem0013-alt.ts
More file actions
34 lines (25 loc) · 653 Bytes
/
Copy pathproblem0013-alt.ts
File metadata and controls
34 lines (25 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @link Problem definition [[docs/projecteuler/problem0013.md]]
*/
import { logger as console } from '../logger';
function problem0013alt(
arrayOfNumbers: string[],
numberOfFirstDigits: number
): number {
const radix = 10;
let sum = BigInt(0);
arrayOfNumbers.forEach((num: string) => {
sum += BigInt(num);
});
console.debug(`Sum: ${sum}`);
const firstDigits = Number.parseInt(
sum.toString().slice(0, numberOfFirstDigits),
radix
);
console.log(
`First ${numberOfFirstDigits} digits of huge sume are ${firstDigits}`
);
return firstDigits;
}
export default problem0013alt;
export { problem0013alt };