day8, part2
This commit is contained in:
parent
3300a8bf3e
commit
77d7355eb7
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
func Run() int {
|
func Run() int {
|
||||||
fmt.Print("hello day 8")
|
fmt.Print("hello day 8")
|
||||||
filename := "day8/example3"
|
filename := "day8/input"
|
||||||
net, path := Read(filename)
|
net, path := Read(filename)
|
||||||
fmt.Printf("got %+v and %+v\n", net, path)
|
fmt.Printf("got %+v and %+v\n", net, path)
|
||||||
result := GhostTraverse(net, path)
|
result := GhostTraverse(net, path)
|
||||||
|
@ -84,6 +84,7 @@ func GhostTraverse(net Network, path Path) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// oh, i don't need to seed the cycle, they are already not equal
|
// oh, i don't need to seed the cycle, they are already not equal
|
||||||
|
cycle := 0
|
||||||
for !allEqual(stepCounts) {
|
for !allEqual(stepCounts) {
|
||||||
max := slices.Max(stepCounts)
|
max := slices.Max(stepCounts)
|
||||||
for i, pathInfo := range pathInfos {
|
for i, pathInfo := range pathInfos {
|
||||||
|
@ -100,7 +101,10 @@ func GhostTraverse(net Network, path Path) int {
|
||||||
stepCounts[i] += overJump
|
stepCounts[i] += overJump
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("done one cycle iteration, results : %+v", stepCounts)
|
cycle += 1
|
||||||
|
if cycle % 10000000 == 0 {
|
||||||
|
log.Printf("done %d cycle iteration, results : %+v", cycle, stepCounts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return stepCounts[0]
|
return stepCounts[0]
|
||||||
|
|
|
@ -27,3 +27,4 @@ so take the difference, if divisible by cycle - yay. just multiply, if not divis
|
||||||
if all are same, that's solution.
|
if all are same, that's solution.
|
||||||
if one is farthest, repeat
|
if one is farthest, repeat
|
||||||
* i stopped bruteforce at 4080000000
|
* i stopped bruteforce at 4080000000
|
||||||
|
the answer was 14935034899483
|
||||||
|
|
Loading…
Reference in New Issue