-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path004.html
55 lines (42 loc) · 959 Bytes
/
004.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function findNDigitFactors(n, x) {
var floorFactor = Math.floor(x / (Math.pow(10, n)));
var ceilFactor = Math.floor(Math.sqrt(x));
// Check if n-digit factors are possible
if (Math.sqrt(x) > (Math.pow(10, n) - 1)) {
return null;
}
for (i = floorFactor; i <= ceilFactor; i++) {
if (isFactor(x, i) && ((x/i) < Math.pow(10, n))) {
return [i, x / i];
}
}
return null;
}
function testPalins() {
for (j = 9; j >= 1; j--) {
for (k = 9; k >= 0; k--) {
for (l = 7; l >= 0; l--) {
var myPalin = (j * 100001) + (k * 10010) + (l * 1100);
var myFactors = findNDigitFactors(3, myPalin);
if (myFactors) { return [myFactors, myPalin]; }
}
}
}
return null;
}
function isFactor(dividend, divisor) {
if ((dividend % divisor) == 0) {
return true;
}
return false;
}
testPalins();
</script>
</body>
</html>