2025-12-03 07:25:24 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
2025-12-03 10:24:16 -06:00
|
|
|
|
2025-12-03 20:47:27 -06:00
|
|
|
"github.com/StevanFreeborn/advent-of-code-2025/cmd/02/rnge"
|
2025-12-03 10:24:16 -06:00
|
|
|
"github.com/StevanFreeborn/advent-of-code-2025/internal/file"
|
2025-12-03 07:25:24 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const SeparatorCharacter = ","
|
|
|
|
|
|
|
|
|
|
func SolvePartOne(filePath string) int64 {
|
2025-12-03 10:24:16 -06:00
|
|
|
input := file.ReadAllText(filePath)
|
|
|
|
|
strRanges := strings.SplitSeq(input, SeparatorCharacter)
|
2025-12-03 07:25:24 -06:00
|
|
|
|
|
|
|
|
total := int64(0)
|
|
|
|
|
|
2025-12-03 20:47:27 -06:00
|
|
|
for r := range strRanges {
|
|
|
|
|
rng := rnge.From(r)
|
2025-12-03 07:25:24 -06:00
|
|
|
|
2025-12-04 06:33:21 -06:00
|
|
|
for id := range rng.InvalidIdsWithEqualHalves() {
|
|
|
|
|
total += id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return total
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SolvePartTwo(filePath string) int64 {
|
|
|
|
|
input := file.ReadAllText(filePath)
|
|
|
|
|
strRanges := strings.SplitSeq(input, SeparatorCharacter)
|
|
|
|
|
|
|
|
|
|
total := int64(0)
|
|
|
|
|
|
|
|
|
|
for r := range strRanges {
|
|
|
|
|
rng := rnge.From(r)
|
|
|
|
|
|
|
|
|
|
for id := range rng.InvalidIdsWithTwoOrMoreSeq() {
|
2025-12-03 07:25:24 -06:00
|
|
|
total += id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return total
|
|
|
|
|
}
|