You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When making pairings between two sets of objects based on their preferences (in this case people), there can be multiple stable solutions, stable meaning that no two elements would prefer to be matched with each other over their current matching.
3
+
When making pairings between two sets of objects based on their preferences \(in this case people\), there can be multiple stable solutions, stable meaning that no two elements would prefer to be matched with each other over their current matching.
4
4
A side-effect of having multiple solutions is that there are solutions favor one group over the other.
5
5
6
6
We received two files, one listing men and the other women. Each line contains a name, followed by a series of numbers. Each number N corresponds to their preference to be matched with the Nth member of the opposite list, with 1 being the highest.
@@ -15,58 +15,47 @@ Here are the lists of preferences:[male preferences](https://github.com/EasyCTF/
15
15
16
16
### Solution
17
17
18
-
When making pairings between two sets of objects based on their preferences (in this case people), there can be multiple stable solutions, stable meaning that no two elements would prefer to be matched with each other over their current matching. A side-effect of having multiple solutions is that there are solutions favor one group over the other.
18
+
This was a fun programming problem! I had already seen the video [https://www.youtube.com/watch?v=Qcv1IqHWAzg](https://www.youtube.com/watch?v=Qcv1IqHWAzg)\(Stable Marriage Problem by Dr Emily Riehl and filmed by Brady Haran from Numberphile\) which happened to describe the algorithm to this exact same problem! I encourage watching it.
19
19
20
-
We received two files, one listing men and the other women.
21
-
Each line contains a name, followed by a series of numbers.
22
-
Each number N corresponds to their preference to be matched with the Nth member of the opposite list, with 1 being the highest.
23
-
24
-
For example, the entry ``"Joe 4, 5, 3, 1, 2"`` means that Joe would most prefer the 4th entry on the opposite list, and least prefer the 2nd.
25
-
26
-
We have heard that there are some pairings that will be together in all possible stable matchings, please find them.
27
-
However, because there are quite a bit of them, please submit your solution as the following:
28
-
29
-
MD5 hash of ``(male_1,female_1)(male_2,female_2)...(male_n,female_n)``, where the pairings are sorted alphabetically by male names. For example, ``(Bob,Susie)(Jim,Carol)(Tom,Emma)`` would be submitted as `b0d75104ce4b3a7d892f745fd515fea4`.
30
-
31
-
Here are the lists of preferences:male preferences, female preferences.
32
-
33
-
----------------------------
34
-
35
-
This was a fun programming problem! I had already seen the video https://www.youtube.com/watch?v=Qcv1IqHWAzg (Stable Marriage Problem by Dr Emily Riehl and filmed by Brady Haran from Numberphile) which happened to describe the algorithm to this exact same problem! I encourage watching it.
36
-
37
-
So the algorithm's description:
38
-
Make an array of all the males, and an array of their ranked preferences of women, where the nth element is the nth male.
39
-
Also create a map between ID's and their name
20
+
So the algorithm's description:
21
+
Make an array of all the males, and an array of their ranked preferences of women, where the nth element is the nth male.
22
+
Also create a map between ID's and their name
40
23
Do the same for females and their rankings of men.
41
24
42
-
Create an array of the men's current pairings, where the nth element is an array of the nth man pairing.
25
+
Create an array of the men's current pairings, where the nth element is an array of the nth man pairing.
43
26
Array has two elements, his personal rank of the woman assigned to him, and that woman's ID.
44
27
45
-
Then create a list of the ID's of all the unassigned woman. (Currently everyone)
28
+
Then create a list of the ID's of all the unassigned woman. \(Currently everyone\)
46
29
Keep going through the following until this list is empty.
47
30
48
-
Iterate through all unassigned women and try assigning them to their top choice man. If the man has a better offer, remove the man from that womans list. (Her top choice, so were always looking at her top available choice. This way we don't ever repeat checking the same M/F combo)
31
+
Iterate through all unassigned women and try assigning them to their top choice man. If the man has a better offer, remove the man from that womans list. \(Her top choice, so were always looking at her top available choice. This way we don't ever repeat checking the same M/F combo\)
49
32
50
33
If the man has her ranked better than who he is already paired with, kick off the person currently paired with the man, and put her ID in the unassignedWomenIDs. Remove person being paired from unassignedWomenIDs.
51
34
52
35
That will finish executing, and then you have all the pairs.
53
36
54
-
Repeat the entire process with man and woman swapped. This gets us the ones that are stable in configurations.
55
-
I wasn't sure if some of these combinations would be unstable in different combos, so if this didn't work then I'd find a way to iterate randomly through unassignedWomenIDs to simulate more configurations.
37
+
Repeat the entire process with man and woman swapped. This gets us the ones that are stable in configurations.
38
+
I wasn't sure if some of these combinations would be unstable in different combos, so if this didn't work then I'd find a way to iterate randomly through unassignedWomenIDs to simulate more configurations.
56
39
I currently don't know if in theory it is possible to have an input with less stable configurations than what this code will detect.
57
40
58
-
Compare the results, and keep only the results that are the same.
41
+
Compare the results, and keep only the results that are the same.
59
42
Format the according string, and md5 it! Thats your flag!
0 commit comments