Skip to content

Instantly share code, notes, and snippets.

@k0d3d
Last active April 19, 2019 10:45
Show Gist options
  • Save k0d3d/427a1e5f8976eb4a72a1c613e68b8033 to your computer and use it in GitHub Desktop.
Save k0d3d/427a1e5f8976eb4a72a1c613e68b8033 to your computer and use it in GitHub Desktop.
Count Prime Number Arrays
function currentNumbers(s, marker) {
let range = new RegExp(`.{1,${marker}}`, 'g')
return s.match(range);
}
const isPrime = num => {
if (!num) return false
if (num < 2) return false
if (num > Math.pow(10, 6)) return false
num = parseInt(num)
for(let i = 2, s = Math.sqrt(num); i <= s; i++)
if(num % i === 0) return false;
return num > 1;
}
let bigres = []
function countPrimeStrings (s, currentShift = 1) {
let maxShiftLenght = s.length
let h = []
currentNumbers(s, currentShift).filter(num => isPrime(num)).forEach(num => h.push(num))
bigres.push(Array.from(new Set(h)))
if (currentShift !== maxShiftLenght) {
return countPrimeStrings(s, ++currentShift)
}
return bigres.filter(oneA => oneA.length).length
}
console.log(countPrimeStrings('13483953'))
// console.log(Array.from(new Set(countPrimeStrings('11455'))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment