-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (30 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const readFile = require("../../utils/readFile");
const input = readFile("2015/day05/input.in").trim();
const findNiceStringsOldRules = (input) => {
let niceStrings = 0;
const words = input.split("\n");
const vowelRegex = /[aeiou]/g;
const doubleLetterRegex = /(.)\1/;
const forbiddenRegex = /(ab|cd|pq|xy)/;
for (let word of words) {
const vowelCount = (word.match(vowelRegex) || []).length;
if (vowelCount >= 3 && doubleLetterRegex.test(word) && !forbiddenRegex.test(word)) {
niceStrings++;
}
}
console.log(`Number of nice strings (Old Rules): ${niceStrings}`);
};
const findNiceStringsNewRules = (input) => {
let niceStrings = 0;
const words = input.split("\n");
const pairTwiceRegex = /(..).*\1/;
const repeatWithGapRegex = /(.).\1/;
for (let word of words) {
if (pairTwiceRegex.test(word) && repeatWithGapRegex.test(word)) {
niceStrings++;
}
}
console.log(`Number of nice strings (New Rules): ${niceStrings}`);
};
findNiceStringsOldRules(input);
findNiceStringsNewRules(input);