forward and backmatches counted
This commit is contained in:
parent
96ac812836
commit
cddf77d09b
1 changed files with 19 additions and 1 deletions
20
4/index.js
20
4/index.js
|
|
@ -1,9 +1,27 @@
|
|||
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")
|
||||
console.log(inputArr)
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue