Check how many of the given strings are nice (not naughty).
const niceStrings = input.split('\n').filter((password) => {
const vowels = password.match(/[aeiou]/g)
if (!vowels || vowels.length < 3) {
return false
}
const hasRepeatingLetter = /([a-z])\1/.test(password)
if (!hasRepeatingLetter) {
return false
}
const hasNaughtyString = /ab|cd|pq|xy/.test(password)
if (hasNaughtyString) {
return false
}
return true
})
console.log(niceStrings.length)
Same as Part 1, but the filtering rules are different.
const niceStrings = input.split('\n').filter((password) => {
const hasDoublePair = /([a-z]{2})[a-z]*\1/.test(password)
const hasRepeatingLetterWithOneLetterInBetween = /([a-z])[a-z]\1/.test(
password
)
return hasDoublePair && hasRepeatingLetterWithOneLetterInBetween
})
console.log(niceStrings.length)
Heh, that one variable name is quite a mouthful.
Nothing. This puzzle was quite similar to the 2020/04 puzzle. (I started doing Advent of Code in 2020.)