From 6d921bbb639d822a5a72ad15d62ed5c42e4cf1c9 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Fri, 12 Dec 2025 06:52:39 -0600 Subject: [PATCH] feat: i came, i saw, and i conquered --- cmd/06/main.go | 35 +++++++++++++++++++++++++++++++++++ cmd/06/main_test.go | 20 ++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/cmd/06/main.go b/cmd/06/main.go index cece549..1bbdeac 100644 --- a/cmd/06/main.go +++ b/cmd/06/main.go @@ -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 +} diff --git a/cmd/06/main_test.go b/cmd/06/main_test.go index 1a93b56..e6837a5 100644 --- a/cmd/06/main_test.go +++ b/cmd/06/main_test.go @@ -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) + } +}