Files
advent-of-code-2024/day19/towelpatterns.go

32 lines
611 B
Go
Raw Normal View History

2024-12-21 15:53:17 +01:00
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)
}