Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 35 KB

05.md

File metadata and controls

59 lines (42 loc) · 35 KB

Day 05

Part 1

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)

Try it out on flems.io

Part 2

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)

flems

Heh, that one variable name is quite a mouthful.

What did I learn?

Nothing. This puzzle was quite similar to the 2020/04 puzzle. (I started doing Advent of Code in 2020.)