74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package day24
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// most inner loop
|
|
// assumint stone hits h1 at t1, and h2 at t2
|
|
// return the line. so 'HailParam' for my stone trajectory
|
|
func AssumeHails(h1, h2 HailParam, t1, t2 int) (stoneTrajectory HailParam, isInt bool) {
|
|
Dx, isXInt := AssumedDelta(h1.p0.x, h2.p0.x, h1.Dx, h2.Dx, t1, t2)
|
|
Dy, isYInt := AssumedDelta(h1.p0.y, h2.p0.y, h1.Dy, h2.Dy, t1, t2)
|
|
Dz, isZInt := AssumedDelta(h1.p0.z, h2.p0.z, h1.Dz, h2.Dz, t1, t2)
|
|
|
|
isInt = isXInt && isYInt && isZInt
|
|
|
|
x := AssumedStartFromDelta(h1.p0.x, h1.Dx, t1, Dx)
|
|
y := AssumedStartFromDelta(h1.p0.y, h1.Dy, t1, Dy)
|
|
z := AssumedStartFromDelta(h1.p0.z, h1.Dz, t1, Dz)
|
|
|
|
stoneTrajectoryLine := fmt.Sprintf("%d, %d, %d @ %d, %d, %d", x, y, z, Dx, Dy, Dz)
|
|
stoneTrajectory = ReadHailLine(stoneTrajectoryLine)
|
|
|
|
return
|
|
}
|
|
|
|
func HailMaryLoop(hails []HailParam) {
|
|
// for t1, t2 from [1, 100]
|
|
// try to fit stoneTrajectory on every pair of hails.
|
|
// and hope for integer fit
|
|
for t1 := 1; t1 <= 100; t1++ {
|
|
for t2 := t1+1 ; t2 <= 100; t2++ {
|
|
for i, hail := range hails {
|
|
innerHail:
|
|
for j, otherHail := range hails {
|
|
if i == j {
|
|
continue innerHail
|
|
}
|
|
_, isInt := AssumeHails(hail, otherHail, t1, t2)
|
|
if !isInt {
|
|
continue innerHail // TODO first hope to loose
|
|
}
|
|
// if isInt {
|
|
// log.Printf("hail mary int fit between %s (%d) and %s (%d)",
|
|
// hail.SomeString(), t1, otherHail.SomeString(), t2)
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO check for inner loop : when get assumed stoneTrajectory
|
|
// for all hail params, check that they intercept
|
|
// func CheckAssumedTrajectory(assumedStone HailParam, hails []HailParam) bool {
|
|
// for _, hail := range hails {
|
|
// // i guess i could try to do what?
|
|
// // assume oh, no. there can be t whatever
|
|
// }
|
|
// }
|
|
|
|
func AssumedDelta(c1, c2 int, Dc1, Dc2 int, t1, t2 int) (delta int, isInt bool) {
|
|
divisor := t1 - t2
|
|
divisible := c1 - c2 + (t1 * Dc1) - (t2 * Dc2)
|
|
|
|
isInt = divisible % divisor == 0
|
|
delta = divisible / divisor
|
|
return
|
|
}
|
|
|
|
func AssumedStartFromDelta(c1 int, Dc1 int, t1, Dc int) (c int) {
|
|
return c1 + t1 * Dc1 - t1 * Dc
|
|
}
|