16 lines
503 B
JavaScript
16 lines
503 B
JavaScript
|
#!/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);
|