-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (48 loc) · 1 KB
/
main.go
File metadata and controls
62 lines (48 loc) · 1 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
package main
import (
"strings"
"github.com/danvolchek/AdventOfCode/lib"
)
func find(line string, substr string, not int) bool {
line = line[0:not] + strings.Repeat("*", len(substr)) + line[not+len(substr):]
return strings.Contains(line, substr)
}
func hasRepeat(line string) bool {
for i := 0; i < len(line)-1; i++ {
if find(line, line[i:i+2], i) {
return true
}
}
return false
}
func hasBetween(line string) bool {
for i := 0; i < len(line)-2; i++ {
if line[i] == line[i+2] {
return true
}
}
return false
}
func solve(lines []string) int {
nice := 0
isNice := func(line string) bool {
return hasRepeat(line) && hasBetween(line)
}
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("qjhvhtzxzqqjkmpb", 1)
solver.Expect("xxyxx", 1)
solver.Expect("uurcxstgmygtbstg", 0)
solver.Expect("ieodomkazucvgmuy", 0)
solver.Verify(53)
}