fix: Project Euler P35 off-by-one error (#1238)

* fix: Project Euler P35 off-by-one error

* Updated Documentation in README.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Lars Müller
2022-10-28 18:51:54 +02:00
committed by GitHub
parent 5364a1c31b
commit 0fab492ceb
2 changed files with 13 additions and 3 deletions

View File

@ -15,7 +15,8 @@ function problem35 (n) {
if (n < 2) {
throw new Error('Invalid input')
}
const list = sieveOfEratosthenes(n).filter(prime => !prime.toString().match(/[024568]/)) // Get a list of primes without 0, 2, 4, 5, 6, 8
// Get a list of primes without 0, 2, 4, 5, 6, 8; this discards the circular primes 2 & 5
const list = sieveOfEratosthenes(n).filter(prime => !prime.toString().match(/[024568]/))
const result = list.filter((number, _idx, arr) => {
const str = String(number)
@ -28,7 +29,7 @@ function problem35 (n) {
return true // If all rotations are prime, then the number is circular prime
})
return result.length + 1 // Add 2 to the result because 2 is a circular prime
return result.length + 2 // Add 2 to the result because the circular primes 2 & 5 were discarded
}
export { problem35 }