Last active
November 5, 2015 08:34
-
-
Save sampritipanda/3a255be92a9b3bcc53c2 to your computer and use it in GitHub Desktop.
Finding all possible bipartite matchings in a set of nodes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recursive(a, b) | |
n = a.length | |
if n == 0 or n == 1 then | |
p b | |
return | |
end | |
(1...n).each do |i| | |
recursive(a - [a[0], a[i]], b + [[a[0], a[i]]]) | |
end | |
end | |
a = %w{Pablo Dan Andrew Tom} | |
recursive(a, []) | |
# Output: | |
# [["Pablo", "Dan"], ["Andrew", "Tom"]] | |
# [["Pablo", "Andrew"], ["Dan", "Tom"]] | |
# [["Pablo", "Tom"], ["Dan", "Andrew"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks @sampritipanda. I just tried that with 8:
and it's not quite generating what we need. That's generating a superset, and what we need is all the unique subsets of that group that make up a pairing assignment for a given day so that you can have people pairing with as many other people as possible without repeats ..
For 8 individuals there are only 7 unique pairings - it's those we want, not this bigger set - but maybe this is a useful start ...