-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday19_1.go
51 lines (41 loc) · 1.09 KB
/
day19_1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package day19
import (
"github.com/blfuentes/AdventOfCode_2024_Go/utilities"
)
func checkIfValid(design string, patterns *map[string]bool, memo *map[string]bool, maxSize int) bool {
initialdesign := design
if value, found := (*memo)[initialdesign]; found {
return value
}
if initialdesign == "" {
(*memo)[initialdesign] = true
return true
}
minlength := min(maxSize, len(initialdesign))
for idx := 1; idx <= minlength; idx++ {
subdesign := initialdesign[:idx]
if (*patterns)[subdesign] {
newsubdesign := initialdesign[idx:]
if checkIfValid(newsubdesign, patterns, memo, maxSize) {
(*memo)[initialdesign] = true
return true
}
}
}
(*memo)[initialdesign] = false
return false
}
func Executepart1() int {
var result int = 0
var fileName string = "./day19/day19.txt"
if fileContent, err := utilities.ReadFileAsText(fileName); err == nil {
patterns, designs, maxSize := parseContent(fileContent)
memo := make(map[string]bool, 0)
for _, design := range designs {
if checkIfValid(design, &patterns, &memo, maxSize) {
result++
}
}
}
return result
}