add day19; to slow to solve part2
This commit is contained in:
31
day19/towelpatterns.go
Normal file
31
day19/towelpatterns.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"os"
|
||||
)
|
||||
|
||||
func check(err error) {
|
||||
if err != nil { panic(err) }
|
||||
}
|
||||
|
||||
func main() {
|
||||
dat, err := os.ReadFile("data.txt")
|
||||
check(err)
|
||||
input := strings.TrimSpace(string(dat))
|
||||
|
||||
towels := strings.Split(input, "\n\n")[0]
|
||||
towels = strings.Replace(towels, ", ", "|", -1)
|
||||
patterns := strings.Split(input, "\n\n")[1]
|
||||
|
||||
r := regexp.MustCompile("^(" + towels + ")+$")
|
||||
|
||||
counter := 0
|
||||
for _, line := range strings.Split(patterns, "\n") {
|
||||
if r.MatchString(line) { counter++ }
|
||||
}
|
||||
|
||||
fmt.Println(counter)
|
||||
}
|
||||
Reference in New Issue
Block a user