feat: solve day 7 part 1
This commit is contained in:
@@ -32,7 +32,7 @@ go test ./cmd/01
|
||||
| 04 | [Problem](https://adventofcode.com/2025/day/4) | [Solution](./cmd/04/) | Part 1 was by far the most straight-forward challenge so far. This was easiest day of AoC this year by far. |
|
||||
| 05 | [Problem](https://adventofcode.com/2025/day/5) | [Solution](./cmd/05/) | Part 1 was fairly straight forward. Merging ranges was trickiest bit. I feel like I'm being led into a trap with how straight forward today was. |
|
||||
| 06 | [Problem](https://adventofcode.com/2025/day/6) | [Solution](./cmd/06/) | Part 1 I don't think it is the best solution, but it does solve it. I kicked ass on part 2. 🥳 |
|
||||
| 07 | [Problem](https://adventofcode.com/2025/day/7) | [Solution](./cmd/07/) | |
|
||||
| 07 | [Problem](https://adventofcode.com/2025/day/7) | [Solution](./cmd/07/) | FIFO for life. 🤣 |
|
||||
| 08 | [Problem](https://adventofcode.com/2025/day/8) | [Solution](./cmd/08/) | |
|
||||
| 09 | [Problem](https://adventofcode.com/2025/day/9) | [Solution](./cmd/09/) | |
|
||||
| 10 | [Problem](https://adventofcode.com/2025/day/10) | [Solution](./cmd/10/) | |
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/StevanFreeborn/advent-of-code-2025/internal/file"
|
||||
"github.com/StevanFreeborn/advent-of-code-2025/internal/position"
|
||||
)
|
||||
|
||||
const StartCharacter = "S"
|
||||
const SplitterCharacter = "^"
|
||||
|
||||
func SolvePartOne(filePath string) int {
|
||||
input := file.ReadAllLines(filePath)
|
||||
numOfRows := len(input)
|
||||
numOfCols := len(input[0])
|
||||
|
||||
startRow := -1
|
||||
startCol := -1
|
||||
|
||||
for row := range numOfRows - 1 {
|
||||
for col := range numOfCols - 1 {
|
||||
v := string(input[row][col])
|
||||
|
||||
if v == StartCharacter {
|
||||
startRow = row
|
||||
startCol = col
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if startRow < 0 || startCol < 0 {
|
||||
panic("unable to find start location")
|
||||
}
|
||||
|
||||
beamStart := position.From(startRow+1, startCol)
|
||||
beamsQueue := []position.Position{
|
||||
beamStart,
|
||||
}
|
||||
visited := map[position.Position]bool{}
|
||||
|
||||
total := 0
|
||||
|
||||
for len(beamsQueue) > 0 {
|
||||
currentBeam := beamsQueue[0]
|
||||
beamsQueue = beamsQueue[1:]
|
||||
|
||||
if visited[currentBeam] {
|
||||
continue
|
||||
}
|
||||
|
||||
if currentBeam.Row() < 0 || currentBeam.Row() >= numOfRows {
|
||||
continue
|
||||
}
|
||||
|
||||
if currentBeam.Column() < 0 || currentBeam.Column() >= numOfCols {
|
||||
continue
|
||||
}
|
||||
|
||||
visited[currentBeam] = true
|
||||
|
||||
value := string(input[currentBeam.Row()][currentBeam.Column()])
|
||||
|
||||
if value == SplitterCharacter {
|
||||
total++
|
||||
rightBeam := position.From(currentBeam.Row(), currentBeam.Column()+1)
|
||||
leftBeam := position.From(currentBeam.Row(), currentBeam.Column()-1)
|
||||
beamsQueue = append(beamsQueue, rightBeam, leftBeam)
|
||||
continue
|
||||
}
|
||||
|
||||
nextBeam := position.From(currentBeam.Row()+1, currentBeam.Column())
|
||||
beamsQueue = append(beamsQueue, nextBeam)
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/07"
|
||||
)
|
||||
|
||||
func TestSolvePartOneWithExampleInput(t *testing.T) {
|
||||
expected := 21
|
||||
|
||||
result := solution.SolvePartOne("EXAMPLE.txt")
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("SolvePartOne() = %d; want %d", result, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSolvePartOneWithInput(t *testing.T) {
|
||||
expected := 1581
|
||||
|
||||
result := solution.SolvePartOne("INPUT.txt")
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("SolvePartOne() = %d; want %d", result, expected)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user