-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.ts
47 lines (38 loc) · 976 Bytes
/
part2.ts
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
import * as fs from 'fs';
const input = fs
.readFileSync('input', 'utf8')
.split('\n')
.map((x) => x.split('').map((y) => ({ height: +y })));
let result = 0;
for (let i = 0; i < input.length; i++) {
for (let j = input[i].length - 1; j >= 0; j--) {
let score = 0;
let scoreSum = 1;
for (let xi = i + 1; xi < input.length; xi++) {
// to right
score++;
if (input[xi][j].height >= input[i][j].height) break;
}
scoreSum *= score;
score = 0;
for (let xi = i - 1; xi >= 0; xi--) {
score++;
if (input[xi][j].height >= input[i][j].height) break;
}
scoreSum *= score;
score = 0;
for (let xj = j + 1; xj < input[0].length; xj++) {
score++;
if (input[i][xj].height >= input[i][j].height) break;
}
scoreSum *= score;
score = 0;
for (let xj = j - 1; xj >= 0; xj--) {
score++;
if (input[i][xj].height >= input[i][j].height) break;
}
scoreSum *= score;
result = Math.max(scoreSum, result);
}
}
console.log(result);