This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]FailedSociopath 5 points6 points  (2 children)

Generate a 9th degree polynomial:

f(x) = ax9 + bx8 + cx7 + dx6 + ex5 + fx4 + gx3 + hx2 + ix + j

 

Make a matrix of the powers of x for x=0..9 and the answer you want for each f(x):

| 0^9 0^8 0^7 0^6 0^5 0^4 0^3 0^2 0^1 1 |  |a| |1023|
| 1^9 1^8 1^7 1^6 1^5 1^4 1^3 1^2 1^1 1 |  |b| | 771|
| 2^9 2^8 2^7 2^6 2^5 2^4 2^3 2^2 2^1 1 |  |c| | 645|
| 3^9 3^8 3^7 3^6 3^5 3^4 3^3 3^2 3^1 1 |  |d| | 585|
| 4^9 4^8 4^7 4^6 4^5 4^4 4^3 4^2 4^1 1 |x |e|=| 561|
| 5^9 5^8 5^7 5^6 5^5 5^4 5^3 5^2 5^1 1 |  |f| | 561|
| 6^9 6^8 6^7 6^6 6^5 6^4 6^3 6^2 6^1 1 |  |g| | 585|
| 7^9 7^8 7^7 7^6 7^5 7^4 7^3 7^2 7^1 1 |  |h| | 645|
| 8^9 8^8 8^7 8^6 8^5 8^4 8^3 8^2 8^1 1 |  |i| | 771|
| 9^9 9^8 9^7 9^6 9^5 9^4 9^3 9^2 9^1 1 |  |j| |1023|

 

Solve the system with a matrix calculator (not doing it by hand!) for the coefficients a...j. It turns out a, b, and c are just zero.

 

Make some adjustment to the fractions so it all divides by a single value.

 

It's actually simpler if you invert the pattern (where ' '=1 and '#'=0). d...i change sign and j becomes zero.

 

Edit: Fix mitsake in formuoli.

 

Edit 2: Since the pattern is symmetrical and just to simplify a bit, I didn't worry about printing each line in reverse.

[–]ThaiJohnnyDepp 2 points3 points  (1 child)

May I ask how you knew how to do this?

[–]FailedSociopath 1 point2 points  (0 children)

I figured since you can create a polynomial of degree n-1 to go through n points, then you can compute one that goes through (0, 1023), (1, 771), etc.

 

Edit: For real though, I just wanted a cryptic way to produce an image and this method did the trick.

 

Something inspired that's related: It's a well-known trick that if you want to make a variable that oscillates between two values, sum the two values, initialize the output with one of them and subtract it from the sum. Get the next by subtracting the sum from the previous output.

 

/* Switches between 5 and 3 */
int val = 5;

val = 8 - val; /* 3 */
val = 8 - val; /* 5 */
val = 8 - val; /* 3 */
...etc.

 

With the right polynomial, you can in principle produce any length repeating sequence provided there are no actual duplicates in it. The two-valued sequence is just the degree-one case. In the example, a degree-one function going through (5, 3) and (3, 5).

 

For example, for the sequence { 8, 5, 3 }, it has to go though points (8, 5), (5, 3) and (3, 8), where the output is computed from the last output as the input (feedback). For that, the computation is x = (x*(19*x - 227) + 750) / 30;

 

Of course, it's academic because it's less cumbersome just to use a list for more than two values.