forward and backmatches counted

This commit is contained in:
Seth Samuel 2025-04-28 08:54:41 +00:00
parent 96ac812836
commit cddf77d09b

View file

@ -1,9 +1,27 @@
const fs = require("fs") const fs = require("fs")
const forwardRegex = /XMAS/g const forwardRegex = /XMAS/g
const backwardRegex = /SAMX/g
const input = fs.readFileSync("input.txt","utf-8") const input = fs.readFileSync("input.txt","utf-8")
const inputArr = input.split("\n") const inputArr = input.split("\n")
console.log(inputArr) let totalMatches= 0;
// console.log(inputArr)
// const forwardMatchs = input.match(forwardRegex) // const forwardMatchs = input.match(forwardRegex)
// console.log(input) // console.log(input)
// console.log(forwardMatchs.length) // console.log(forwardMatchs.length)
//create a sliding window to match the words //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)