File tree 1 file changed +12
-9
lines changed 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -6,23 +6,26 @@ import (
6
6
"strings"
7
7
)
8
8
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
14
11
15
12
func main () {
16
13
17
- input , err := os .ReadFile ("./input/input6.txt" )
18
- check (err )
14
+ input , _ := os .ReadFile ("./input/input6.txt" )
19
15
20
16
lines := strings .Split (string (input ), "\r \n " )
21
17
22
18
for _ , line := range lines {
23
19
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 )
26
29
break
27
30
}
28
31
}
You can’t perform that action at this time.
0 commit comments