feat: solve P2, same as P1 but check every time the dial passes through 0 during the rotation

This commit is contained in:
2025-12-01 07:41:50 +01:00
parent daec5a8671
commit 0949840317

View File

@@ -39,5 +39,25 @@ func PartOne(data []string) int {
} }
func PartTwo(data []string) int { func PartTwo(data []string) int {
return 0 position := 50
count := 0
for _, rotation := range data {
direction := rotation[0]
distance, _ := strconv.Atoi(rotation[1:])
for range distance {
if direction == 'L' {
position = (position - 1 + 100) % 100
} else {
position = (position + 1) % 100
}
if position == 0 {
count++
}
}
}
return count
} }