The Walsh matrix is an interesting fractal matrix with the property that every single value in a Walsh matrix has a value of either -1 or 1. Additionally, the size of a Walsh matrix is always a power of 2.
Because each Walsh matrix is identical to the top-left quarter of the immediately higher-order Walsh matrix, we can create a generalized "infinite Walsh matrix" by considering the limit of the sequence of Walsh matrices of order N, as N goes to infinity. From here on, we will call this infinite generalization the Walsh matrix.
Your task is to build a program that takes the coordinates of a location in the Walsh matrix and returns the value that occurs there.
Your program will accept two integers x
and y
as input (in any form you choose), and output the value that appears in the x+1
th row of the y+1
th column of the Walsh matrix. For example, the input
2 5
will return 1
, as the 3rd row in the 6th column of the Walsh matrix has a value of 1. The input
6 4
will return -1
, as the 7th row in the 5th column of the Walsh matrix has a value of -1. The input
2834719 394802
will return -1
, as the 2384720th row of the 394803rd column has a value of -1.
The shortest code to do this in any language wins.
print "0 ± 1"
\$\endgroup\$1
you'll do better than 50%. \$\endgroup\$