Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Picking pairs of objects from a list of 6

  1. Jan 14, 2015 #1
    Given a list (a,b,c,d,e,f) What method can I use to quickly find all 15 pairings of two letters. I can do it without using a specific decision procedure throughout but sometimes combinations get repeated and its hard to check quickly which ones have already been. Essentially I would like an algorithm to find every combination of pairs in a set of arbitrary length/
     
  2. jcsd
  3. Jan 14, 2015 #2

    Quantum Defect

    User Avatar
    Homework Helper
    Gold Member

    Loop from x = 1 to N-1

    [ Loop from y= x+1 to N

    pair = list[x], list [y] ]
     
  4. Jan 14, 2015 #3
    i dont follow that. Please note I dont know programming i need a more wordy answer please
     
  5. Jan 14, 2015 #4

    Quantum Defect

    User Avatar
    Homework Helper
    Gold Member

    list (1..N) => list = (a, b, c, d, e, f); N = number of members in the list; in this case, N = 6

    The loops above, look like:

    x=1, y = 2, 3, 4, 5, 6: pairs = (a,b), (a,c), (a,d), (a,e), (a,f)
    x=2, y = 3, 4, 5, 6: pairs = (b, c), (b,d), (b,e), (b,f)
    x=3, y = 4, 5, 6: pairs = (c,d), (c,e), (c,f)
    x=4, y=5, 6,: pairs = (d,e), (d,f)
    x=5, y = 6: pairs = (e,f)
     
  6. Jan 14, 2015 #5
    I've just realised i have not asked the question i meant to ask sorry. What I meant was the find all the sets consisting of 3 uniques pairs from (a,b,c,d,e,f) so e.g. one will be
    ((a,b),(c,d),(e,f)) and another would be ((a,c),(b,e),(d,f))
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook