Skip to content

Commit 71ff27f

Browse files
committed
add day 6 part 2
1 parent aa6888d commit 71ff27f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

day6.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,26 @@ import (
66
"strings"
77
)
88

9-
func check(e error) {
10-
if e != nil {
11-
panic(e)
12-
}
13-
}
9+
// const MARKER = 4 // Part 1
10+
const MARKER = 14 // Part 2
1411

1512
func main() {
1613

17-
input, err := os.ReadFile("./input/input6.txt")
18-
check(err)
14+
input, _ := os.ReadFile("./input/input6.txt")
1915

2016
lines := strings.Split(string(input), "\r\n")
2117

2218
for _, line := range lines {
2319
for i := 0; i < len(line); i++ {
24-
if line[i] != line[i+1] && line[i+1] != line[i+2] && line[i+2] != line[i+3] && line[i] != line[i+2] && line[i+1] != line[i+3] && line[i] != line[i+3] {
25-
fmt.Println("Part1: ", i+4)
20+
seen := map[byte]int{line[i]: 1}
21+
for j := i + 1; j < i+MARKER; j++ {
22+
if _, ok := seen[line[j]]; ok {
23+
break
24+
}
25+
seen[line[j]] = 1
26+
}
27+
if len(seen) == MARKER {
28+
fmt.Println("Solution: ", i+MARKER)
2629
break
2730
}
2831
}

0 commit comments

Comments
 (0)