From d61a63060751425ded65d6beb9b8ea5625571301 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Tue, 2 Dec 2025 07:18:38 -0600 Subject: [PATCH 1/4] feat: ugh...this shouldn't be that hard --- cmd/01/dial/dial.go | 52 ++++++++++++++++++++++++++++++++++++++-- cmd/01/dial/dial_test.go | 19 +++++++++++++++ cmd/01/main.go | 16 +++++++++++++ cmd/01/main_test.go | 26 ++++++++++++++++++++ internal/file/file.go | 2 -- 5 files changed, 111 insertions(+), 4 deletions(-) diff --git a/cmd/01/dial/dial.go b/cmd/01/dial/dial.go index e75f273..a9b69d5 100644 --- a/cmd/01/dial/dial.go +++ b/cmd/01/dial/dial.go @@ -2,35 +2,75 @@ package dial import ( + "fmt" + "github.com/StevanFreeborn/advent-of-code-2025/cmd/01/direction" "github.com/StevanFreeborn/advent-of-code-2025/cmd/01/instruction" ) type Dial interface { + ZeroCount() int Value() int Turn(instruction instruction.Instruction) } type dial struct { - value int + zeroCount int + value int } func New() Dial { return &dial{ - value: 50, + zeroCount: 0, + value: 50, } } +func From(value int) Dial { + return &dial{ + zeroCount: 0, + value: value, + } +} + +func (d *dial) ZeroCount() int { + return d.zeroCount +} + func (d *dial) Value() int { return d.value } func (d *dial) Turn(instruction instruction.Instruction) { + logPrefix := fmt.Sprintf("[TURN %s %d]", instruction.Direction(), instruction.Distance()) + + if d.value < 0 || d.value > 99 { + panic("NEVER SHALL YOU PASS!!!") + } + + // d.value is always 0 to 99 + if instruction.Direction() == direction.Left { + if d.value == 0 { + d.zeroCount-- + } + d.value -= instruction.Distance() + // that here we are at 0 + + if d.value == 0 { + fmt.Printf("%s zeroCount++\n", logPrefix) + d.zeroCount++ + } + for d.value < 0 { + // WE NEVER GET HERE + // UNLESS d.value is -1 or less + currentValue := d.value + d.zeroCount++ d.value += 100 + fmt.Printf("%s zeroCount++ => Correcting %d to %d (%d)\n", logPrefix, currentValue, d.value, d.zeroCount) } return @@ -39,8 +79,16 @@ func (d *dial) Turn(instruction instruction.Instruction) { if instruction.Direction() == direction.Right { d.value += instruction.Distance() + // that here we at 100 or the equilavent + // of 0. this is counted + for d.value > 99 { + // WE NEVER GET HERE + // UNLESS d.value is 100 or more + currentValue := d.value + d.zeroCount++ d.value -= 100 + fmt.Printf("%s zeroCount++ => Correcting %d to %d (%d)\n", logPrefix, currentValue, d.value, d.zeroCount) } return diff --git a/cmd/01/dial/dial_test.go b/cmd/01/dial/dial_test.go index 37c13cf..e50ca8a 100644 --- a/cmd/01/dial/dial_test.go +++ b/cmd/01/dial/dial_test.go @@ -16,6 +16,25 @@ func TestNew(t *testing.T) { } } +func TestProblem(t *testing.T) { + instructions := []instruction.Instruction{ + instruction.FromLine("R48"), + instruction.FromLine("L5"), + } + + dial := dial.From(52) + + for _, i := range instructions { + dial.Turn(i) + } + + result := dial.ZeroCount() + + if result != 1 { + t.Errorf("ya done fucked up. you wanted %d but got %d", 1, result) + } +} + type TurnTestCase struct { Instruction instruction.Instruction ExpectedDialValue int diff --git a/cmd/01/main.go b/cmd/01/main.go index 2247a83..d064824 100644 --- a/cmd/01/main.go +++ b/cmd/01/main.go @@ -26,3 +26,19 @@ func SolvePartOne(filePath string) int { return total } + +func SolvePartTwo(filePath string) int { + lines := file.ReadLines(filePath) + dial := dial.New() + + for _, line := range lines { + if line == "" { + continue + } + + instruction := instruction.FromLine(line) + dial.Turn(instruction) + } + + return dial.ZeroCount() +} diff --git a/cmd/01/main_test.go b/cmd/01/main_test.go index c69c8f5..25c51ef 100644 --- a/cmd/01/main_test.go +++ b/cmd/01/main_test.go @@ -25,3 +25,29 @@ func TestSolvePartOneWithInput(t *testing.T) { t.Errorf(`SolvePartOne("INPUT.txt") = %d; want %d`, result, expected) } } + +func TestSolvePartTwoWithExampleInput(t *testing.T) { + expected := 6 + + result := solution.SolvePartTwo("EXAMPLE.txt") + + if result != expected { + t.Errorf(`SolvePartTwo("EXAMPLE.txt") = %d; want %d`, result, expected) + } +} + +func TestSolvePartTwoWithInput(t *testing.T) { + expected := -1 + tooLow := 5849 + tooHigh := 5967 + + result := solution.SolvePartTwo("INPUT.txt") + + if result <= tooLow || result >= tooHigh { + t.Errorf(`SolvePartTwo("INPUT.txt") = %d; want something between %d and %d`, result, tooLow, tooHigh) + } + + if result != expected { + t.Errorf(`SolvePartTwo("INPUT.txt") = %d; want %d`, result, expected) + } +} diff --git a/internal/file/file.go b/internal/file/file.go index ce90c26..b76a3fd 100644 --- a/internal/file/file.go +++ b/internal/file/file.go @@ -3,7 +3,6 @@ package file import ( "bufio" - "fmt" "os" ) @@ -20,7 +19,6 @@ func ReadLines(filePath string) []string { for hasLine := scanner.Scan(); hasLine; hasLine = scanner.Scan() { line := scanner.Text() - fmt.Println(line) lines = append(lines, line) } From c1c9d4157df1618dc16a1031cf212bab77663fe0 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Tue, 2 Dec 2025 07:33:49 -0600 Subject: [PATCH 2/4] feat: fuck me...only count occurrences of landing on and then beginning on zero once --- cmd/01/dial/dial.go | 62 ++++++++++++++++++--------------------------- cmd/01/main_test.go | 2 +- 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/cmd/01/dial/dial.go b/cmd/01/dial/dial.go index a9b69d5..219a3c0 100644 --- a/cmd/01/dial/dial.go +++ b/cmd/01/dial/dial.go @@ -2,8 +2,6 @@ package dial import ( - "fmt" - "github.com/StevanFreeborn/advent-of-code-2025/cmd/01/direction" "github.com/StevanFreeborn/advent-of-code-2025/cmd/01/instruction" ) @@ -42,55 +40,43 @@ func (d *dial) Value() int { } func (d *dial) Turn(instruction instruction.Instruction) { - logPrefix := fmt.Sprintf("[TURN %s %d]", instruction.Direction(), instruction.Distance()) - - if d.value < 0 || d.value > 99 { - panic("NEVER SHALL YOU PASS!!!") - } - - // d.value is always 0 to 99 - if instruction.Direction() == direction.Left { - if d.value == 0 { - d.zeroCount-- - } + for range instruction.Distance() { + d.decreaseOneClick() - d.value -= instruction.Distance() + if d.value == 0 { + d.zeroCount++ + } - // that here we are at 0 - - if d.value == 0 { - fmt.Printf("%s zeroCount++\n", logPrefix) - d.zeroCount++ - } - - for d.value < 0 { - // WE NEVER GET HERE - // UNLESS d.value is -1 or less - currentValue := d.value - d.zeroCount++ - d.value += 100 - fmt.Printf("%s zeroCount++ => Correcting %d to %d (%d)\n", logPrefix, currentValue, d.value, d.zeroCount) + if d.value < 0 { + d.value += 100 + } } return } if instruction.Direction() == direction.Right { - d.value += instruction.Distance() + for range instruction.Distance() { + d.increaseOneClick() - // that here we at 100 or the equilavent - // of 0. this is counted + if d.value >= 100 { + d.value -= 100 + } - for d.value > 99 { - // WE NEVER GET HERE - // UNLESS d.value is 100 or more - currentValue := d.value - d.zeroCount++ - d.value -= 100 - fmt.Printf("%s zeroCount++ => Correcting %d to %d (%d)\n", logPrefix, currentValue, d.value, d.zeroCount) + if d.value == 0 { + d.zeroCount++ + } } return } } + +func (d *dial) decreaseOneClick() { + d.value-- +} + +func (d *dial) increaseOneClick() { + d.value++ +} diff --git a/cmd/01/main_test.go b/cmd/01/main_test.go index 25c51ef..67ef371 100644 --- a/cmd/01/main_test.go +++ b/cmd/01/main_test.go @@ -38,7 +38,7 @@ func TestSolvePartTwoWithExampleInput(t *testing.T) { func TestSolvePartTwoWithInput(t *testing.T) { expected := -1 - tooLow := 5849 + tooLow := 5922 tooHigh := 5967 result := solution.SolvePartTwo("INPUT.txt") From 0bc711e1866175a281b2e73ec1ff514b149cd849 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Tue, 2 Dec 2025 07:37:39 -0600 Subject: [PATCH 3/4] chore: update README.md --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 734bfcf..75fd6d4 100644 --- a/README.md +++ b/README.md @@ -20,17 +20,17 @@ Each day's solution is contained in a separate package. ## Challenges -| Day | Problem | Solution | Notes | -|-----|-------------------------------------------------|-----------------------|----------------------------------------| -| 01 | [Problem](https://adventofcode.com/2025/day/1) | [Solution](./cmd/01/) | Part 1 seemed straight forward enough. | -| 02 | [Problem](https://adventofcode.com/2025/day/2) | [Solution](./cmd/02/) | | -| 03 | [Problem](https://adventofcode.com/2025/day/3) | [Solution](./cmd/03/) | | -| 04 | [Problem](https://adventofcode.com/2025/day/4) | [Solution](./cmd/04/) | | -| 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/) | | -| 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/) | | -| 11 | [Problem](https://adventofcode.com/2025/day/11) | [Solution](./cmd/11/) | | -| 12 | [Problem](https://adventofcode.com/2025/day/12) | [Solution](./cmd/12/) | | +| Day | Problem | Solution | Notes | +|-----|-------------------------------------------------|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 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/) | | +| 03 | [Problem](https://adventofcode.com/2025/day/3) | [Solution](./cmd/03/) | | +| 04 | [Problem](https://adventofcode.com/2025/day/4) | [Solution](./cmd/04/) | | +| 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/) | | +| 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/) | | +| 11 | [Problem](https://adventofcode.com/2025/day/11) | [Solution](./cmd/11/) | | +| 12 | [Problem](https://adventofcode.com/2025/day/12) | [Solution](./cmd/12/) | | From e1bb9d8beb56b5cb61ac88181d6fdf901923f801 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Tue, 2 Dec 2025 07:40:47 -0600 Subject: [PATCH 4/4] tests: add right answer --- cmd/01/main_test.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cmd/01/main_test.go b/cmd/01/main_test.go index 67ef371..1e175bb 100644 --- a/cmd/01/main_test.go +++ b/cmd/01/main_test.go @@ -37,16 +37,10 @@ func TestSolvePartTwoWithExampleInput(t *testing.T) { } func TestSolvePartTwoWithInput(t *testing.T) { - expected := -1 - tooLow := 5922 - tooHigh := 5967 + expected := 5937 result := solution.SolvePartTwo("INPUT.txt") - if result <= tooLow || result >= tooHigh { - t.Errorf(`SolvePartTwo("INPUT.txt") = %d; want something between %d and %d`, result, tooLow, tooHigh) - } - if result != expected { t.Errorf(`SolvePartTwo("INPUT.txt") = %d; want %d`, result, expected) }