refactor: add positions method to grid and use that for iterating in day 4 part 1
This commit is contained in:
+8
-19
@@ -1,12 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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 = "@"
|
||||
@@ -17,26 +14,18 @@ func SolvePartOne(filePath string) int {
|
||||
|
||||
total := 0
|
||||
|
||||
for row := range grid.NumberOfRows() {
|
||||
for column := range grid.NumberOfColumns() {
|
||||
currentPosition := position.From(row, column)
|
||||
value := grid.GetValueAt(currentPosition)
|
||||
for position := range grid.Positions() {
|
||||
value := grid.GetValueAt(position)
|
||||
|
||||
if value != PaperRollCharacter {
|
||||
continue
|
||||
}
|
||||
if value != PaperRollCharacter {
|
||||
continue
|
||||
}
|
||||
|
||||
sameNeighbors := grid.GetSameNeighborsOf(currentPosition, move.AllDirections)
|
||||
sameNeighbors := grid.GetSameNeighborsOf(position, move.AllDirections)
|
||||
|
||||
if row == 0 && column == 3 {
|
||||
fmt.Println(sameNeighbors)
|
||||
}
|
||||
|
||||
if len(sameNeighbors) < 4 {
|
||||
total++
|
||||
}
|
||||
if len(sameNeighbors) < 4 {
|
||||
total++
|
||||
}
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user