32 lines
611 B
Go
32 lines
611 B
Go
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)
|
|
}
|