-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproblem0007.js
More file actions
35 lines (25 loc) · 693 Bytes
/
problem0007.js
File metadata and controls
35 lines (25 loc) · 693 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
35
/**
* @link Problem definition [[docs/projecteuler/problem0007.md]]
*/
import { logger as console } from '../logger.js';
import { isPrime } from './helpers/index.js';
function problem0007(_top) {
const primes = [];
let i = 0;
let j = 2;
while (primes.length < _top) {
i += 1;
if (isPrime(j)) {
primes.push(j);
console.debug(`Prime found ${j} put in position: ${primes.length}`);
}
j = 2 * i + 1;
}
console.log(`primes count: ${primes.length}`);
const answer = primes.at(-1);
const cycles = i;
console.log(`${_top} prime number is: ${answer} in ${cycles} cycles`);
return answer;
}
export default problem0007;
export { problem0007 };