Add 2024/day4/part2.js

This commit is contained in:
x0x7 2024-12-04 18:10:58 -05:00
parent f0a02d0f5d
commit f396302693
1 changed files with 16 additions and 0 deletions

16
2024/day4/part2.js Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env node
var input = require('fs').readFileSync(process.argv[2]||'input.txt','utf8').split('\n').filter(i=>i);
var width = input.length;
var sum=0;
for(var i=1;i<width-1;++i) {
for(var j=1;j<width-1;++j) {
var isXMAS = input[i][j]=='A' && ((input[i-1][j-1]=='M'&&input[i+1][j+1]=='S') || (input[i-1][j-1]=='S'&&input[i+1][j+1]=='M')) && ((input[i-1][j+1]=='M'&&input[i+1][j-1]=='S') || (input[i-1][j+1]=='S'&&input[i+1][j-1]=='M'))
if(isXMAS) ++sum;
}
}
console.log('Result:',sum);