-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday4.js
51 lines (37 loc) · 954 Bytes
/
day4.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
let result = 0;
for(let i = 0; i < 999999; i++) {
let t = i.toString();
if(i < 254032 || i > 789860) {continue; }
if(t.length !== 6) { continue; }
if(!hasTwoDigits(t)) { continue; }
if(!digitsAreIncreasing(t)) {continue; }
result++;
}
console.log("Result: ", result);
function hasTwoDigits(num) {
for(let i = 0; i < 10; i++)
{
let digits = num.indexOf(i.toString().repeat(2));
let digits3 = num.indexOf(i.toString().repeat(3));
if(digits === -1) { continue; }
if(digits !== digits3) {
return true;
}
// if((digits === 0 && digits3 === 4)||()) {
// return true;
// }
}
return false;
}
function digitsAreIncreasing(num) {
let last = 0;
for(let index in num) {
if (last <= num[index]) {
last = num[index];
}
else {
return false;
}
}
return true;
}