-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (57 loc) · 1.19 KB
/
main.go
File metadata and controls
74 lines (57 loc) · 1.19 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"strings"
"unicode/utf8"
"github.com/danvolchek/AdventOfCode/lib"
)
func countVowels(line string) int {
vowels := 0
for _, r := range line {
if r == 'a' || r == 'e' || r == 'i' || r == 'o' || r == 'u' {
vowels += 1
}
}
return vowels
}
func hasDouble(line string) bool {
curr, _ := utf8.DecodeRune([]byte(line[0:1]))
for _, next := range line[1:] {
if curr == next {
return true
}
curr = next
}
return false
}
func doesNotHave(line string, bad []string) bool {
for _, badString := range bad {
if strings.Contains(line, badString) {
return false
}
}
return true
}
func solve(lines []string) int {
nice := 0
isNice := func(line string) bool {
return countVowels(line) >= 3 && hasDouble(line) && doesNotHave(line, []string{"ab", "cd", "pq", "xy"})
}
for _, line := range lines {
if isNice(line) {
nice += 1
}
}
return nice
}
func main() {
solver := lib.Solver[[]string, int]{
ParseF: lib.ParseLine(lib.AsIs),
SolveF: solve,
}
solver.Expect("tugknbfddgicrmopn", 1)
solver.Expect("taaa", 1)
solver.Expect("jchzalrnumimnmhp", 0)
solver.Expect("haegwjzuvuyypxyu", 0)
solver.Expect("dvszwmarrgswjxmb", 0)
solver.Verify(258)
}