Public
Edited
Dec 1, 2023
Insert cell
Insert cell
Insert cell
function isNice(s) {
const atLeastThreeVowels = (s.match(/[aeiou]/g) || []).length >= 3;
const doubleLetter = /(.)\1/.test(s);
const forbidden = /ab|cd|pq|xy/.test(s);

return atLeastThreeVowels && doubleLetter && !forbidden;
}
Insert cell
Insert cell
function part1(input) {
return input.split("\n").filter(isNice).length;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function isNice2(s) {
const hasRepeatPair = /(..).*\1/.test(s);
const hasABA = /(.).\1/.test(s);
return hasRepeatPair && hasABA;
}
Insert cell
function part2(input) {
return input.split("\n").filter(isNice2).length;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more