-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path35.js
37 lines (33 loc) · 969 Bytes
/
35.js
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
36
37
var out = require("./timer");
var optimus = require("./optimus");
var numbers = require("./numbers");
function permutable_prime(test_num) {
var num = test_num.toString().split("");
var check,perm = numbers.firstPermutation(num);
console.log(perm.join(""));
if (!optimus.isPrime(perm.join("")/1)) return false;
while ((check=numbers.lexiPermutation(perm)) != perm) {
if (!optimus.isPrime(check.join("")/1)) {return false;}
perm=check;
}
return true;
}
function circular_prime(test_num) {
var num = test_num.toString().split("");
if (!optimus.isPrime(num.join("")/1)) return false;
for (var i in num) {
num.unshift(num.pop());
if (!optimus.isPrime(num.join("")/1)) return false;
}
return true;
}
var prime=1;
var count = 0;
var max = 1000000;
while (optimus.getPrime(prime)<max) {
if (circular_prime(optimus.getPrime(prime))){
count++;
}
prime++;
}
out.print(count);