mirror of
https://github.com/tiennm99/adventofcode.git
synced 2026-10-14 20:16:53 +00:00
feat(2025): optimize day1 part2
This commit is contained in:
1 parent
7f49236d21
commit
2b4ddffbcf
1 file changed
+10
-6
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@@ -22,13 +23,16 @@ func main() {
|
|||||||
multiplier = -1
|
multiplier = -1
|
||||||
}
|
}
|
||||||
number, _ := strconv.Atoi(line[1:])
|
number, _ := strconv.Atoi(line[1:])
|
||||||
for range number {
|
prevCurrent := current
|
||||||
current += multiplier
|
current += number * multiplier
|
||||||
current = ((current % 100) + 100) % 100
|
counter += int(math.Floor(math.Abs(float64(current) / 100)))
|
||||||
if current == 0 {
|
if prevCurrent*current < 0 {
|
||||||
counter++
|
counter++
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if current == 0 {
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
current = ((current % 100) + 100) % 100
|
||||||
}
|
}
|
||||||
fmt.Printf("%d\n", counter)
|
fmt.Printf("%d\n", counter)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user