First optimizations
This gets runtime down to about a quarter of what it was. I need to see if I can apply bisect to the X value, but I'm not sure I understand how/if that can work.
This commit is contained in:
20
days/19.go
20
days/19.go
@ -89,34 +89,34 @@ func (d *Day19) Part2() string {
|
||||
}
|
||||
}
|
||||
|
||||
done := false
|
||||
for y := startY; !done; y++ {
|
||||
lastGoodX := 0
|
||||
threshold := 1
|
||||
y := u.Bisect(startY+100, 9999, threshold, func(y int) bool {
|
||||
foundX := false
|
||||
for x := startX; ; x++ {
|
||||
if !f(x, y) {
|
||||
if !foundX {
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
return true
|
||||
}
|
||||
}
|
||||
if !foundX {
|
||||
foundX = true
|
||||
startX = x
|
||||
}
|
||||
|
||||
if !f(x+99, y) {
|
||||
break
|
||||
return true
|
||||
}
|
||||
if !f(x, y+99) {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("x=%d, y=%d, so result=%d\n", x, y, (x*10000)+y)
|
||||
done = true
|
||||
break
|
||||
lastGoodX = x
|
||||
return false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return "0"
|
||||
result := (lastGoodX * 10000) + y
|
||||
return fmt.Sprintf("Closest 100x100 square for the ship starts at %d,%d = %s%d%s", lastGoodX, y, u.TextBold, result, u.TextReset)
|
||||
}
|
||||
|
Reference in New Issue
Block a user