Related Articles

# Puzzle 82 | Different Pairings

• Difficulty Level : Hard
• Last Updated : 08 Feb, 2018

Joey has to arrange 2N sandwiches which are wrapped by different color wrapper in N pairs such that he can feed his N girlfriends (A hypothetical situation it is where we have to ignore the fact “JOEY DOESN’T SHARE FOOD ”). He has to serve them for 2N-1 Days. Girls don’t like repeated pair of color wrapper of their sandwiches.
Design an algorithm for joey so that for 2N-1 days no pair would be same.

Hint: One can solve problem by using 2*N table.

Solution:
Here is one of the way to generate 2N-1 sets of different pairs efficiently. For convenience, number the different color from 1 to 2N and place these numbers in a 2N table. The pairs for the first set are given by the columns of this table. To generate the next 2N −2 sets, rotate—say, clockwise—all the entries except 1 in the last generated table.
Figure shows the example for N = 3. The entry 1 is fixed and all other entries are rotated clockwise.

References:  The algorithm can be thought of as based on the representation change strategy. Both interpretations of the algorithm outlined above were given by Maurice Kraitchik in Mathematical Recreations [Kra53, pp. 226–227].