27 lines
No EOL
726 B
JavaScript
27 lines
No EOL
726 B
JavaScript
const fs = require("fs")
|
|
const forwardRegex = /XMAS/g
|
|
const backwardRegex = /SAMX/g
|
|
const input = fs.readFileSync("input.txt","utf-8")
|
|
const inputArr = input.split("\n")
|
|
let totalMatches= 0;
|
|
// console.log(inputArr)
|
|
// const forwardMatchs = input.match(forwardRegex)
|
|
// console.log(input)
|
|
// console.log(forwardMatchs.length)
|
|
//create a sliding window to match the words
|
|
|
|
|
|
for (row of inputArr){
|
|
// console.log(row)
|
|
const forwardMatches = row.match(forwardRegex)
|
|
const backwordsMatches= row.match(backwardRegex)
|
|
|
|
if(forwardMatches){
|
|
totalMatches += forwardMatches.length
|
|
}
|
|
if(backwordsMatches){
|
|
totalMatches += backwordsMatches.length
|
|
}
|
|
}
|
|
|
|
console.log("totalMatches: ",totalMatches) |