feat: i came, i saw, and i conquered

This commit is contained in:
Stevan Freeborn
2025-12-12 06:52:39 -06:00
parent de34aaac5a
commit 6d921bbb63
2 changed files with 55 additions and 0 deletions
+35
View File
@@ -33,3 +33,38 @@ func SolvePartOne(filePath string) int {
return total
}
func SolvePartTwo(filePath string) int {
input := file.ReadAllLines(filePath)
numOfRows := len(input)
operatorRowIndex := numOfRows - 1
operatorRow := input[operatorRowIndex]
operatorRowLength := len(operatorRow)
total := 0
operands := []int{}
for operatorIndex := operatorRowLength - 1; operatorIndex >= 0; operatorIndex-- {
var operandBuilder strings.Builder
for row := range numOfRows - 1 {
v := string(input[row][operatorIndex])
operandBuilder.WriteString(v)
}
operandString := strings.TrimSpace(operandBuilder.String())
operand, _ := strconv.Atoi(operandString)
operands = append(operands, operand)
operandBuilder.Reset()
operator := string(operatorRow[operatorIndex])
if operator != " " {
total += problem.From(operator, operands).Solve()
operatorIndex--
operands = []int{}
}
}
return total
}
+20
View File
@@ -25,3 +25,23 @@ func TestSolvePartOneWithInput(t *testing.T) {
t.Errorf("got %d but wanted %d", result, expected)
}
}
func TestSolvePartTwoWithExampleInput(t *testing.T) {
expected := 3263827
result := solution.SolvePartTwo("EXAMPLE.txt")
if result != expected {
t.Errorf("got %d but wanted %d", result, expected)
}
}
func TestSolvePartTwoWithInput(t *testing.T) {
expected := 10442199710797
result := solution.SolvePartTwo("INPUT.txt")
if result != expected {
t.Errorf("got %d but wanted %d", result, expected)
}
}