-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd05.ts
More file actions
59 lines (47 loc) · 1.45 KB
/
d05.ts
File metadata and controls
59 lines (47 loc) · 1.45 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Day, RegisterDay } from "../Day.ts";
@RegisterDay(2015, 5)
export class Day05 extends Day {
override partOne(): string {
let naughty_str: Array<string> = ["ab", "cd", "pq", "xy"];
let vowels: Array<string> = ["a", "e", "i", "o", "u"];
let niceWords: number = 0;
for (let str of this.readInput().split("\n")) {
if (naughty_str.filter((item) => str.indexOf(item) != -1).length > 0) {
continue;
}
let vowelsCount = 0;
let containsConsecutive = false;
for (let i = 0; i < str.split("").length; i++) {
if (vowels.includes(str[i])) vowelsCount++;
if (i != 0 && !containsConsecutive) {
if (str[i] == str[i - 1]) containsConsecutive = true;
}
}
if (vowelsCount >= 3 && containsConsecutive) {
niceWords++;
}
}
return niceWords.toString();
}
override partTwo(): string {
let niceWords: number = 0;
for (let str of this.readInput().split("\n")) {
let check_1 = false;
let check_2 = false;
for (let i = 0; i < str.split("").length; i++) {
if (i == 0) continue;
const repeat = str.match(new RegExp(str.substr(i - 1, 2), "g"));
if (repeat != null && repeat.length > 1) {
check_1 = true;
}
if (i > 1 && str[i] == str[i - 2]) {
check_2 = true;
}
}
if (check_1 && check_2) {
niceWords++;
}
}
return niceWords.toString();
}
}