Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb94e5f9

Browse files
committed
[UPDATE] Change sieve algorithm implementation and now the solution
works well. Also added some optimizations
1 parente88994f commitb94e5f9

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
functionproblem35(n){
1515
if(n<2){
1616
thrownewError('Invalid input')
1717
}
18-
constlist=sieveOfEratosthenes(n)
18+
constlist=sieveOfEratosthenes(n).filter(prime=>!prime.toString().match(/[024568]/))// Get a list of primes without 0, 2, 4, 5, 6, 8
1919

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

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

3434
export{problem35}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp