This commit is contained in:
Aelita4 2022-12-08 23:08:37 +01:00
parent 8b0e3b518c
commit 69b0f79024
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
1 changed files with 10 additions and 2 deletions

View File

@ -4,7 +4,7 @@ const input = readFileSync("trees.txt", "utf-8");
const arr = []; const arr = [];
let howManyVisible = 0, width, height = 0; let howManyVisible = 0, width, height = 0, highestScenicScore = 0;
input.split("\n").forEach(line => { input.split("\n").forEach(line => {
width = line.length; width = line.length;
@ -22,8 +22,10 @@ for(let row = 0; row < height; row++) {
} }
const checkFor = arr[row][column]; const checkFor = arr[row][column];
let hiddenNorth = false, hiddenSouth = false, hiddenWest = false, hiddenEast = false; 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--) { for(let i = row - 1; i >= 0; i--) {
howManyNorth++;
if(checkFor <= arr[i][column] && row !== i) { if(checkFor <= arr[i][column] && row !== i) {
hiddenNorth = true; hiddenNorth = true;
break; break;
@ -31,6 +33,7 @@ for(let row = 0; row < height; row++) {
} }
for(let i = column - 1; i >= 0; i--) { for(let i = column - 1; i >= 0; i--) {
howManyWest++;
if(checkFor <= arr[row][i] && column !== i) { if(checkFor <= arr[row][i] && column !== i) {
hiddenWest = true; hiddenWest = true;
break; break;
@ -38,6 +41,7 @@ for(let row = 0; row < height; row++) {
} }
for(let i = row + 1; i < height; i++) { for(let i = row + 1; i < height; i++) {
howManySouth++;
if(checkFor <= arr[i][column] && row !== i) { if(checkFor <= arr[i][column] && row !== i) {
hiddenSouth = true; hiddenSouth = true;
break; break;
@ -45,6 +49,7 @@ for(let row = 0; row < height; row++) {
} }
for(let i = column + 1; i < width; i++) { for(let i = column + 1; i < width; i++) {
howManyEast++;
if(checkFor <= arr[row][i] && column !== i) { if(checkFor <= arr[row][i] && column !== i) {
hiddenEast = true; hiddenEast = true;
break; break;
@ -57,7 +62,10 @@ for(let row = 0; row < height; row++) {
hiddenWest && hiddenWest &&
hiddenEast hiddenEast
)) howManyVisible++; )) howManyVisible++;
const checkForHighestScore = howManyNorth * howManySouth * howManyWest * howManyEast;
if(checkForHighestScore > highestScenicScore) highestScenicScore = checkForHighestScore;
} }
} }
console.log(howManyVisible) console.log(howManyVisible, highestScenicScore)