-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05.ts
31 lines (28 loc) · 1.11 KB
/
05.ts
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
import { L } from "../../common/language.ts";
// "It contains at least three vowels"
const threeWovels = new RegExp(`^(?=(.*[${L.wovels}]){3})`);
// "It contains at least one letter that appears twice in a row"
const letterTwiceInARow = /(\w)\1/;
// "It does not contain the strings ab, cd, pq, or xy"
const forbiddenWords = /(ab|cd|pq|xy)/;
// "It contains a pair of any two letters that appears at least twice
// in the string without overlapping"
const twoPairsOfTwoLetters = /(\w{2}).*\1/;
// "It contains at least one letter which repeats with
// exactly one letter between them"
const repeatingWithOneBetween = /(\w).\1/;
// Find how many lines in the input are nice according to first rule set
export function part1(input: string) {
return input.split("\n").filter((s) => (
threeWovels.test(s) &&
letterTwiceInARow.test(s) &&
!forbiddenWords.test(s)
)).length;
}
// Find how many lines in the input are nice according to second rule set
export function part2(input: string) {
return input.split("\n").filter((s) => (
twoPairsOfTwoLetters.test(s) &&
repeatingWithOneBetween.test(s)
)).length;
}