"Bridge sorting" problem
reddit.com·17h·
Discuss: r/compsci

For context, I am an amateur bridge player, and in many cases, it helps to sort my hand in 13 cards in alternating colors from greatest to least so I can see what cards I am working with, so that basically inspired this problem.

Suppose you have a list of integer tuples (a_1, b_1), (a_2, b_2), ..., (a_n, b_n). You wish to arrange the list in a certain order that meets the following three criteria:

All tuples with first element a_i are grouped together. That is, you shouldn’t have a spare a_i anywhere else. 1. Within a grouping with first element a_i, the group is ordered in decreasing order of the b_i’s. 1. Two adjacent groupings identified by elements a_i != a_j must have a_i and a_j differ in parity IF POSSIBLE. That is, if a_i is even, then all adjace…

Similar Posts

Loading similar posts...