Files
advent-of-code-2025/cmd/12/main.go
T

51 lines
1.1 KiB
Go
Raw Normal View History

2025-12-23 08:18:01 -06:00
package main
import (
2025-12-24 08:35:14 -06:00
"regexp"
2025-12-23 08:18:01 -06:00
"strings"
"github.com/StevanFreeborn/advent-of-code-2025/cmd/12/region"
2025-12-23 08:18:01 -06:00
"github.com/StevanFreeborn/advent-of-code-2025/cmd/12/shape"
"github.com/StevanFreeborn/advent-of-code-2025/internal/file"
)
const COLON = ":"
const X = "x"
func SolvePartOne(filePath string) int {
2025-12-24 08:35:14 -06:00
twoNewLineRegex := regexp.MustCompile(`\r?\n\r?\n`)
newLineRegex := regexp.MustCompile(`\r?\n`)
2025-12-23 08:18:01 -06:00
2025-12-24 08:35:14 -06:00
input := file.ReadAllText(filePath)
sections := twoNewLineRegex.Split(strings.TrimSpace(input), -1)
total := 0
shapes := map[int][]shape.Shape{}
regions := []region.Region{}
2025-12-23 08:18:01 -06:00
for _, section := range sections {
2025-12-24 08:35:14 -06:00
lines := newLineRegex.Split(strings.TrimSpace(section), -1)
2025-12-23 08:18:01 -06:00
header := lines[0]
if strings.Contains(header, COLON) && strings.Contains(header, X) == false {
2025-12-24 08:35:14 -06:00
shape := shape.From(lines)
shapes[shape.Id()] = shape.GenerateVariants()
2025-12-23 08:18:01 -06:00
continue
}
for _, line := range lines {
if strings.Contains(line, COLON) {
regions = append(regions, region.From(line))
2025-12-23 08:18:01 -06:00
}
}
}
2025-12-24 08:35:14 -06:00
for _, region := range regions {
if region.CanFit(shapes) {
2025-12-24 08:35:14 -06:00
total++
2025-12-23 08:18:01 -06:00
}
}
2025-12-24 08:35:14 -06:00
return total
}