-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (66 loc) · 1.14 KB
/
main.go
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
package main
import (
_ "embed"
"fmt"
"strings"
. "github.com/beanz/advent/lib-go"
)
//go:embed input.txt
var input []byte
func nice(s string) (bool, bool) {
vc := 0
hasDouble := false
badPair := false
dupPair := false
sepRepeat := false
for i := 0; i < len(s); i++ {
if s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' {
vc++
}
if i == len(s)-1 {
continue
}
if s[i] == s[i+1] {
hasDouble = true
}
if (s[i] == 'a' && s[i+1] == 'b') ||
(s[i] == 'c' && s[i+1] == 'd') ||
(s[i] == 'p' && s[i+1] == 'q') ||
(s[i] == 'x' && s[i+1] == 'y') {
badPair = true
}
if strings.Count(s, s[i:i+2]) >= 2 {
dupPair = true
}
if i == len(s)-2 {
continue
}
if s[i] == s[i+2] {
sepRepeat = true
}
}
return vc >= 3 && hasDouble && !badPair, dupPair && sepRepeat
}
func calc(in []string) (int, int) {
c1 := 0
c2 := 0
for _, s := range in {
p1, p2 := nice(s)
if p1 {
c1++
}
if p2 {
c2++
}
}
return c1, c2
}
func main() {
in := InputLines(input)
p1, p2 := calc(in)
if !benchmark {
fmt.Printf("Part 1: %d\n", p1)
fmt.Printf("Part 2: %d\n", p2)
}
}
var benchmark bool