|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "gonum.org/v1/gonum/mat" |
| 7 | +) |
| 8 | + |
| 9 | +const Steps = 26501365 |
| 10 | + |
| 11 | +func main() { |
| 12 | + m := parse() |
| 13 | + |
| 14 | + // Find the 3 points necessary to generate the parabola coefficients |
| 15 | + |
| 16 | + var points [3]P |
| 17 | + |
| 18 | + for i, steps := range []int{ |
| 19 | + m.Size / 2, // reach the border, fill one tile |
| 20 | + m.Size/2 + m.Size, // 5 tiles |
| 21 | + m.Size/2 + 2*m.Size, // 13 tiles |
| 22 | + } { |
| 23 | + cells := Reach(m, steps) |
| 24 | + points[i] = P{steps, cells} |
| 25 | + } |
| 26 | + |
| 27 | + // Given these 3 points, we can find a,b,c such as |
| 28 | + // y = a*x^2 + b*x + c |
| 29 | + a, b, c := FindParabola(points) |
| 30 | + |
| 31 | + fmt.Println(int(a*Steps*Steps + b*Steps + c)) |
| 32 | +} |
| 33 | + |
| 34 | +func FindParabola(p [3]P) (float64, float64, float64) { |
| 35 | + A := mat.NewDense(3, 3, []float64{ |
| 36 | + float64(p[0].x * p[0].x), float64(p[0].x), 1, |
| 37 | + float64(p[1].x * p[1].x), float64(p[1].x), 1, |
| 38 | + float64(p[2].x * p[2].x), float64(p[2].x), 1, |
| 39 | + }) |
| 40 | + |
| 41 | + y := mat.NewVecDense(3, []float64{float64(p[0].y), float64(p[1].y), float64(p[2].y)}) |
| 42 | + |
| 43 | + var b mat.VecDense |
| 44 | + _ = b.SolveVec(A, y) |
| 45 | + |
| 46 | + return b.AtVec(0), b.AtVec(1), b.AtVec(2) |
| 47 | +} |
0 commit comments