4

If you have a list of items and you want to randomly pair the items in the list together, what kind of algorithm would you use to do that, such that the items can only be matched to one other item.

yannis
39.7k40 gold badges185 silver badges218 bronze badges
asked Nov 29, 2011 at 1:49

1 Answer 1

9

Randomize the list and then grab pairs of adjacent items.

(I'm not sure I understand your last requirement, "the items can only be matched to one other item." If I haven't fully answered your question, please edit the question to expand on that point.)

answered Nov 29, 2011 at 1:56
2
  • I could be wrong, but I think the only way to interpret that last line is that if you generate a pair A-C (out of a list of values from A-Z) none of the other pairs can have either A or C. Repeat this until all items have been paired-off. So in a list of items numbering 'n' (where n is even), there will be 'n'/2 pairs with no pairs having an element in common. Commented Nov 29, 2011 at 4:38
  • That is correct Dan. Commented Nov 29, 2011 at 4:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.