Merge pull request #9 from StevanFreeborn/stevanfreeborn/feat/solve-day-four-part-one

feat: solve day four part one
This commit is contained in:
Stevan Freeborn
2025-12-07 08:03:02 -06:00
committed by GitHub
3 changed files with 110 additions and 1 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ go test ./cmd/01
| 01 | [Problem](https://adventofcode.com/2025/day/1) | [Solution](./cmd/01/) | Part 1 seemed straight forward enough. Part 2 completely stumped me. The trickiest part was not counting zero's twice when you ended and then started from there. |
| 02 | [Problem](https://adventofcode.com/2025/day/2) | [Solution](./cmd/02/) | Part 1 should have been super straight-forward, but some whitespace screwed up my parsing of the final range. I some how was able to stumble over a solution to part 2 rather blindly. |
| 03 | [Problem](https://adventofcode.com/2025/day/3) | [Solution](./cmd/03/) | Part 1 intuitively makes you think you only care about highest nums, but then you need to consider placement. I once again tripped over the solution using a stack. However chat morally supported me the whole time. |
| 04 | [Problem](https://adventofcode.com/2025/day/4) | [Solution](./cmd/04/) | |
| 04 | [Problem](https://adventofcode.com/2025/day/4) | [Solution](./cmd/04/) | Part 1 was by far the most straight-forward challenge so far. |
| 05 | [Problem](https://adventofcode.com/2025/day/5) | [Solution](./cmd/05/) | |
| 06 | [Problem](https://adventofcode.com/2025/day/6) | [Solution](./cmd/06/) | |
| 07 | [Problem](https://adventofcode.com/2025/day/7) | [Solution](./cmd/07/) | |
+82
View File
@@ -0,0 +1,82 @@
package main
import (
"github.com/StevanFreeborn/advent-of-code-2025/internal/file"
)
const PaperRollCharacter = "@"
const EmptyCharacter = "."
type move struct {
NumberOfRows int
NumberOfColumns int
}
var (
up = move{NumberOfRows: -1, NumberOfColumns: 0}
down = move{NumberOfRows: 1, NumberOfColumns: 0}
right = move{NumberOfRows: 0, NumberOfColumns: 1}
left = move{NumberOfRows: 0, NumberOfColumns: -1}
upRight = move{NumberOfRows: -1, NumberOfColumns: 1}
upLeft = move{NumberOfRows: -1, NumberOfColumns: -1}
downRight = move{NumberOfRows: 1, NumberOfColumns: 1}
downLeft = move{NumberOfRows: 1, NumberOfColumns: -1}
)
var moves = []move{
up,
down,
right,
left,
upRight,
upLeft,
downRight,
downLeft,
}
func SolvePartOne(filePath string) int {
input := file.ReadAllLines(filePath)
numberOfRows := len(input)
numberOfColumns := len(input[0])
total := 0
for row := range numberOfRows {
for column := range numberOfColumns {
value := string(input[row][column])
if value != PaperRollCharacter {
continue
}
numberOfPaperRolls := 0
for _, move := range moves {
neighborRow := row + move.NumberOfRows
neighborColumn := column + move.NumberOfColumns
if neighborRow > numberOfRows-1 || neighborRow < 0 {
continue
}
if neighborColumn > numberOfColumns-1 || neighborColumn < 0 {
continue
}
neighborValue := string(input[neighborRow][neighborColumn])
if neighborValue != PaperRollCharacter {
continue
}
numberOfPaperRolls++
}
if numberOfPaperRolls < 4 {
total++
}
}
}
return total
}
+27
View File
@@ -0,0 +1,27 @@
package main_test
import (
"testing"
solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/04"
)
func TestSolvePartOneWithExampleInput(t *testing.T) {
expected := 13
result := solution.SolvePartOne("EXAMPLE.txt")
if result != expected {
t.Errorf("got %d but wanted %d", result, expected)
}
}
func TestSolvePartOneWithInput(t *testing.T) {
expected := 1395
result := solution.SolvePartOne("INPUT.txt")
if result != expected {
t.Errorf("got %d but wanted %d", result, expected)
}
}