Skip to content

Commit b94e5f9

Browse files
committed
[UPDATE] Change sieve algorithm implementation and now the solution
works well. Also added some optimizations
1 parent e88994f commit b94e5f9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Project-Euler/Problem035.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
*
1010
* @author ddaniel27
1111
*/
12-
import { sieveOfEratosthenes } from '../Maths/SieveOfEratosthenes'
12+
import { sieveOfEratosthenes } from '../Maths/SieveOfEratosthenesIntArray'
1313

1414
function problem35 (n) {
1515
if (n < 2) {
1616
throw new Error('Invalid input')
1717
}
18-
const list = sieveOfEratosthenes(n)
18+
const list = sieveOfEratosthenes(n).filter(prime => !prime.toString().match(/[024568]/)) // Get a list of primes without 0, 2, 4, 5, 6, 8
1919

2020
const result = list.filter((number, _idx, arr) => {
2121
const str = String(number)
@@ -28,7 +28,7 @@ function problem35 (n) {
2828
return true // If all rotations are prime, then the number is circular prime
2929
})
3030

31-
return result.length
31+
return result.length + 1 // Add 2 to the result because 2 is a circular prime
3232
}
3333

3434
export { problem35 }

0 commit comments

Comments
 (0)