#include <stdio.h>
int main()
{
int i;
int x;
int y;
for (x = 1; x <= 5; x++)
{
for (y = 1; y <= 5; y++)
{
i = 7848 + y * (-29412 + y * (23130 + y * (-6660 + y * 630)))
+ x * (-16668 + y * (56629 + y * (-44066 + y * (12612 + y * -1186))))
+ x * x * (11910 + y * (-35522 + y * (27183 + y * (-7696 + y * 717))))
+ x * x * x * (-3420 + y * (9204 + y * (-6844 + y * (1908 + y * -176))))
+ x * x * x * x * (330 + y * (-826 + y * (597 + y * (-164 + y * 15))));
printf("%2d ", i/72);
}
printf("\n");
}
}
The output is:
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
What mathematic basis is behind this code?
EDIT: I know this code is useless and worthless, and can’t be used in any other way. I am just curious about the mathematical basis behind this code…
This looks like someone’s attempt to do something simple in a deliberately complicated way.
For each cell, it is calculating a polynomial in
xandy. The value at each cell is a sum of termsaijxiyjfor all 0<=i<=4 and 0<=j<=4.To calculate the coefficients
aijof the polynomial, you can substitute the values ofxandyand the desired result for each cell. You’d get 25 linear equations with 25 variables, which can be solved with basic linear algebra.Note that this method has nothing to do with the result being a spiral pattern: It could be used to print any result, the coefficients would just be different.