-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler-p1-4.js
87 lines (77 loc) · 1.39 KB
/
euler-p1-4.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 1, 1, 2, 3, 5, 8, 13, 21, ...
function fib(i) {
if (i <= 2)
return 1
return fib(i-1) + fib(i-2)
}
// 1, 1, 2, 3
//
function bigPrimeFactor(n){
var p
for (var it = 1; it < (n / 2); it++){
if (n % it === 0){
if(isPrime(it))
p = it
}
}
return p
}
// 6
// it: 2; 2 < (6 / 2) -> 6%2 == 0
// 7
// it: 2; 2 < (7 / 2) -> 7%2 != 0
// it: 3; 3 < (7 / 3) -> 7%3 != 0
// it: 4; 4 < (7 / 4) -> bail
function isPrime(n){
if (n === 1) return true
for (var it = 2; it < (n / it); it++){
if (n % it === 0){
return false
}
}
return true
}
function prob(n){
return bigPrimeFactor(n)
}
function giveMirrors(n){
var arr = []
if (n ===1)
return series(10)
for(let it = 1; it < n; it++){
arr.push(x)
}
}
function loop(n){
var arr = +'9'.repeat(n)
var i = 0;
var curr
var greatest = 0
for (var x = arr; x > 0; x--) {
for (var y = arr; y >= x; y--) {
curr = x * y
if (isMirror(curr) && curr > greatest) {
greatest = curr
}
}
}
return greatest
}
function isMirror(x){
x = x.toString()
var n = x.length
for (var i = 0; i < n; i++){
x1 = x[n - 1 - i]
x2 = x[i]
if (x1 !== x2){
return false
}
}
return true
}
function series(n) {
return Array.apply(null, Array(n)).map((x, i) => i)
}
function foo(a, b, c) {
console.log(this, a, b, c)
}