Skip to content

Instantly share code, notes, and snippets.

@foxwhite25
Created December 6, 2022 09:40
Show Gist options
  • Save foxwhite25/510070d2d73e37c7fd08ada6c4190962 to your computer and use it in GitHub Desktop.
Save foxwhite25/510070d2d73e37c7fd08ada6c4190962 to your computer and use it in GitHub Desktop.
AOC-2022-Day6
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