Add 2024/day4/part2.js
This commit is contained in:
parent
f0a02d0f5d
commit
f396302693
|
@ -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);
|
Loading…
Reference in New Issue