This commit is contained in:
2023-07-16 12:03:13 -05:00
parent 462d12f502
commit 0a1837263f
2 changed files with 40 additions and 0 deletions

32
daysix.go Normal file
View File

@@ -0,0 +1,32 @@
package main
func areUnique(inputs [4]byte) bool {
switch {
case inputs[0] == inputs[1]:
case inputs[0] == inputs[2]:
case inputs[0] == inputs[3]:
case inputs[1] == inputs[2]:
case inputs[1] == inputs[3]:
case inputs[2] == inputs[3]:
return false
}
return true
}
func daySix(input string) (marker int) {
var a, b, c, d byte
marker = 4
for i := 3; i < len(input); i++ {
a, b, c, d = input[i-3], input[i-2], input[i-1], input[i]
if areUnique([4]byte{a, b, c, d}) {
return
}
marker++
}
return -1
}

View File

@@ -102,4 +102,12 @@ func main() {
for _, r := range dayFiveResult {
fmt.Printf("%c ", r)
}
/** DAY SIX */
fmt.Println("\nDAY SIX")
fmt.Println(daySix("bvwbjplbgvbhsrlpgdmjqwftvncz"))
fmt.Println(daySix("nppdvjthqldpwncqszvftbrmjlhg"))
fmt.Println(daySix("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"))
fmt.Println(daySix("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"))
}