08_2
This commit is contained in:
parent
8b0e3b518c
commit
69b0f79024
|
@ -4,7 +4,7 @@ const input = readFileSync("trees.txt", "utf-8");
|
|||
|
||||
const arr = [];
|
||||
|
||||
let howManyVisible = 0, width, height = 0;
|
||||
let howManyVisible = 0, width, height = 0, highestScenicScore = 0;
|
||||
|
||||
input.split("\n").forEach(line => {
|
||||
width = line.length;
|
||||
|
@ -22,8 +22,10 @@ for(let row = 0; row < height; row++) {
|
|||
}
|
||||
const checkFor = arr[row][column];
|
||||
let hiddenNorth = false, hiddenSouth = false, hiddenWest = false, hiddenEast = false;
|
||||
let howManyNorth = 0, howManySouth = 0, howManyWest = 0, howManyEast = 0;
|
||||
|
||||
for(let i = row - 1; i >= 0; i--) {
|
||||
howManyNorth++;
|
||||
if(checkFor <= arr[i][column] && row !== i) {
|
||||
hiddenNorth = true;
|
||||
break;
|
||||
|
@ -31,6 +33,7 @@ for(let row = 0; row < height; row++) {
|
|||
}
|
||||
|
||||
for(let i = column - 1; i >= 0; i--) {
|
||||
howManyWest++;
|
||||
if(checkFor <= arr[row][i] && column !== i) {
|
||||
hiddenWest = true;
|
||||
break;
|
||||
|
@ -38,6 +41,7 @@ for(let row = 0; row < height; row++) {
|
|||
}
|
||||
|
||||
for(let i = row + 1; i < height; i++) {
|
||||
howManySouth++;
|
||||
if(checkFor <= arr[i][column] && row !== i) {
|
||||
hiddenSouth = true;
|
||||
break;
|
||||
|
@ -45,6 +49,7 @@ for(let row = 0; row < height; row++) {
|
|||
}
|
||||
|
||||
for(let i = column + 1; i < width; i++) {
|
||||
howManyEast++;
|
||||
if(checkFor <= arr[row][i] && column !== i) {
|
||||
hiddenEast = true;
|
||||
break;
|
||||
|
@ -57,7 +62,10 @@ for(let row = 0; row < height; row++) {
|
|||
hiddenWest &&
|
||||
hiddenEast
|
||||
)) howManyVisible++;
|
||||
|
||||
const checkForHighestScore = howManyNorth * howManySouth * howManyWest * howManyEast;
|
||||
if(checkForHighestScore > highestScenicScore) highestScenicScore = checkForHighestScore;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(howManyVisible)
|
||||
console.log(howManyVisible, highestScenicScore)
|
Loading…
Reference in New Issue