feat: fuck me...only count occurrences of landing on and then beginning on zero once

This commit is contained in:
Stevan Freeborn
2025-12-02 07:33:49 -06:00
parent d61a630607
commit c1c9d4157d
2 changed files with 25 additions and 39 deletions
+24 -38
View File
@@ -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++
}
+1 -1
View File
@@ -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")