Day 6
This commit is contained in:
13
day06/common/signal.go
Normal file
13
day06/common/signal.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Signal string
|
||||||
|
|
||||||
|
|
||||||
|
func Parse(scanner bufio.Scanner) Signal {
|
||||||
|
scanner.Scan()
|
||||||
|
return Signal(scanner.Text())
|
||||||
|
}
|
||||||
26
day06/ex1/main.go
Normal file
26
day06/ex1/main.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"aoc2022/day06/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
signal := common.Parse(*bufio.NewScanner(os.Stdin))
|
||||||
|
index := 0
|
||||||
|
|
||||||
|
for i := 4; i <= len(signal); i++ {
|
||||||
|
set := make(map[rune]bool)
|
||||||
|
for _, c := range signal[i-4:i] {
|
||||||
|
set[c] = true
|
||||||
|
}
|
||||||
|
if len(set) == 4 {
|
||||||
|
index = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(index)
|
||||||
|
}
|
||||||
26
day06/ex2/main.go
Normal file
26
day06/ex2/main.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"aoc2022/day06/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
signal := common.Parse(*bufio.NewScanner(os.Stdin))
|
||||||
|
index := 0
|
||||||
|
|
||||||
|
for i := 14; i <= len(signal); i++ {
|
||||||
|
set := make(map[rune]bool)
|
||||||
|
for _, c := range signal[i-14:i] {
|
||||||
|
set[c] = true
|
||||||
|
}
|
||||||
|
if len(set) == 14 {
|
||||||
|
index = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(index)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user