Symmetric Pairs

  • + 0 comments

    O is an alias for the outer query Functions and I is an alias for the inner query Functions.

    The (O.x=O.y) part is just a cute trick common in programming languages, since it's a boolean value, but it gets implicitly cast to an integer value (0=false, 1=true) and here detects duplicate pairs.

    So if O.x,O.y=22,22 in one row only, then the WHERE clause is false = (1 < 1). As explained in the first post, if the symmetric pair occurs exactly twice, then the WHERE clause is true = (1 < 2). The problem is that the testcases are not robust enough to force us to distinguish higher numbers of occurrences. If the symmetric pair occurs exactly thrice, then the third occurrence should be ignored. If it occurs exactly four times, then the third & fourth occurrences should be paired and distinct from the pair of the first & second, but as commented my code doesn't go that far.