79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
package day24
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func SystemsWithSymbols() (result string) {
|
|
result += "\n"
|
|
coords := []string{"x", "y", "z"}
|
|
for i := 0; i < 3; i++ {
|
|
for _, coord := range coords {
|
|
result += fmt.Sprintf("%s + D%s * t%d == %s%d + D%s%d * t%d\n",
|
|
coord, coord, i, coord, i, coord, i, i)
|
|
}
|
|
}
|
|
|
|
result += "solve for x, y, z, Dx, Dy, Dz, t1, t2, t3. ti > 0"
|
|
|
|
return
|
|
}
|
|
|
|
func SystemFromThreeHailstones(hails []HailParam) (result string) {
|
|
result += "\n"
|
|
coords := []string{"x", "y", "z"}
|
|
for i := 0; i < 3; i++ {
|
|
result += fmt.Sprintf("t%d >= 0\n", i)
|
|
hailIter := hails[i]
|
|
for _, coord := range coords {
|
|
result += fmt.Sprintf("%s + D%s * t%d == %d + %d * t%d\n",
|
|
coord, coord, i,
|
|
hailIter.GetCoord(coord), hailIter.GetSpeedOf(coord), i)
|
|
}
|
|
}
|
|
|
|
result += "solve for x, y, z, Dx, Dy, Dz, t1, t2, t3."
|
|
return
|
|
}
|
|
|
|
func SystemFromThreeHailstonesToTheLeft(hails []HailParam) (result string) {
|
|
result += "\n"
|
|
coords := []string{"x", "y", "z"}
|
|
for i := 0; i < 3; i++ {
|
|
result += fmt.Sprintf("t%d >= 0\n", i)
|
|
hailIter := hails[i]
|
|
for _, coord := range coords {
|
|
result += fmt.Sprintf("%s + D%s * t%d - (%d * t%d) == %d \n",
|
|
coord, coord, i,
|
|
hailIter.GetSpeedOf(coord), i, hailIter.GetCoord(coord))
|
|
}
|
|
}
|
|
|
|
result += "solve for x, y, z, Dx, Dy, Dz, t1, t2, t3."
|
|
return
|
|
}
|
|
|
|
func SystemAsPythonInit(hails []HailParam) (result string) {
|
|
result += "\n"
|
|
coords := []string{"x", "y", "z"}
|
|
for _, coord := range coords {
|
|
result += fmt.Sprintf("%s = Real('%s')\n", coord, coord)
|
|
result += fmt.Sprintf("D%s = Real('D%s')\n", coord, coord)
|
|
}
|
|
|
|
for i := 0; i < 3; i++ {
|
|
result += fmt.Sprintf("t%d = Real('t%d')\n", i, i)
|
|
result += fmt.Sprintf("eqT%d = t%d >= 0\n", i, i)
|
|
hailIter := hails[i]
|
|
for _, coord := range coords {
|
|
result += fmt.Sprintf("eq%d%s = %s + D%s * t%d == (%d * t%d) + %d \n",
|
|
i, coord,
|
|
coord, coord, i,
|
|
hailIter.GetSpeedOf(coord), i, hailIter.GetCoord(coord))
|
|
}
|
|
}
|
|
|
|
result += "//solve for x, y, z, Dx, Dy, Dz, t1, t2, t3."
|
|
return
|
|
}
|