Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

One of my friends asked me this.. What does this represent? Some string?

   A B C D
 A = > < >
 B < = < <
 C > > = >
 D < > < =

the only thing I have been able to get till now is C>A>D>B

share|improve this question

closed as off topic by Griffin, w0lf, PhiNotPi, Howard, Mr.Wizard Aug 20 '12 at 9:24

Questions on Programming Puzzles & Code Golf Stack Exchange are expected to relate to programming puzzle or code golf within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

It represents a strict linear order on the set whose elements are A,B,C,D. A simple program can extract the order in "linear form" from such a matrix, e.g. by coding <,=,> as 1,0,-1 respectively, and A,B,C,D,... as 0,1,2,3,... respectively.

Here's the program from the link, applied to your question:

def order_from_matrix(m):
    return [(len(m) - 1 - sum(row)) // 2 for row in m] 

order_from_matrix([[ 0, -1,  1, -1],
                   [ 1,  0,  1,  1],
                   [-1, -1,  0, -1],
                   [ 1, -1,  1,  0]])

This produces the output

[2, 0, 3, 1]

which represents

C > A > D > B

NB: The given matrix is interpreted such that the symbols in the first row = > < > mean A=A, A>B, A<C, A>D, coded as [ 0, -1, 1, -1], and so on for the other rows. This is the interpretation consistent with C > A > D > B stated by the OP; however, the "opposite" interpretation is also possible, but would correspond to a different ordering.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.