Created
December 6, 2022 09:40
-
-
Save foxwhite25/510070d2d73e37c7fd08ada6c4190962 to your computer and use it in GitHub Desktop.
AOC-2022-Day6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io/ioutil" | |
"strings" | |
) | |
func main() { | |
input, err := ioutil.ReadFile("./6/input.txt") | |
if err != nil { | |
panic(err) | |
} | |
inputStr := strings.TrimSpace(string(input)) | |
k := 14 | |
//Find the first index where 14 letters are all different | |
//Put the 14 letter in a set and see if the set has 4 elements | |
for i := 0; i < len(inputStr)-k+1; i++ { | |
set := make(map[byte]bool) | |
for j := 0; j < k; j++ { | |
set[inputStr[i+j]] = true | |
} | |
if len(set) == k { | |
println(i + k) | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment