add day19; to slow to solve part2

This commit is contained in:
2024-12-21 15:53:17 +01:00
parent 7272fee707
commit 636a704dde
3 changed files with 502 additions and 0 deletions

31
day19/towelpatterns.go Normal file
View 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)
}