feat: solve day 4 part 2

This commit is contained in:
Stevan Freeborn
2025-12-08 05:39:47 -06:00
parent 801b492e59
commit 0b74bfd821
4 changed files with 89 additions and 1 deletions
+37
View File
@@ -4,9 +4,11 @@ import (
"github.com/StevanFreeborn/advent-of-code-2025/internal/file"
"github.com/StevanFreeborn/advent-of-code-2025/internal/grid"
"github.com/StevanFreeborn/advent-of-code-2025/internal/move"
"github.com/StevanFreeborn/advent-of-code-2025/internal/position"
)
const PaperRollCharacter = "@"
const EmptySpaceCharacter = "."
func SolvePartOne(filePath string) int {
input := file.ReadAllLines(filePath)
@@ -27,5 +29,40 @@ func SolvePartOne(filePath string) int {
total++
}
}
return total
}
func SolvePartTwo(filePath string) int {
input := file.ReadAllLines(filePath)
g := grid.From(input)
total := 0
for {
positionsToRemove := []position.Position{}
for position := range g.Positions() {
value := g.GetValueAt(position)
if value != PaperRollCharacter {
continue
}
sameNeighbors := g.GetSameNeighborsOf(position, move.AllDirections)
if len(sameNeighbors) < 4 {
positionsToRemove = append(positionsToRemove, position)
total++
}
}
if len(positionsToRemove) == 0 {
break
}
g.SetValuesAt(positionsToRemove, EmptySpaceCharacter)
}
return total
}