Skip to content

Commit 51e0f5b

Browse files
committed
Updates programming/match-me-300-points.md
Auto commit by GitBook Editor
1 parent dab7c6c commit 51e0f5b

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

programming/match-me-300-points.md

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Match Me - 300 points
22

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.
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.
44
A side-effect of having multiple solutions is that there are solutions favor one group over the other.
55

66
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/
1515

1616
### Solution
1717

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.
1919

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
4023
Do the same for females and their rankings of men.
4124

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.
4326
Array has two elements, his personal rank of the woman assigned to him, and that woman's ID.
4427

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\)
4629
Keep going through the following until this list is empty.
4730

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\)
4932

5033
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.
5134

5235
That will finish executing, and then you have all the pairs.
5336

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.
5639
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.
5740

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.
5942
Format the according string, and md5 it! Thats your flag!
6043

6144
Pairs:
45+
6246
```
6347
(Adonis,Aja)(Aidan,Eden)(Alvaro,Ciara)(Andres,Melanie)(Anton,Dominique)(Aric,Randi)(Arron,Kathleen)(Austyn,Sonya)(Blair,Suzanne)(Braden,Carlee)(Brayan,Meagan)(Brendan,Karley)(Bret,Dalia)(Brock,Cora)(Brooks,Alaina)(Daron,Bryanna)(Davon,Georgia)(Devan,Doris)(Diamond,Kristi)(Dimitri,Zoe)(Donavan,Arlene)(Edward,Kaitlyn)(Everett,Renee)(Fabian,Leslie)(Francis,Kimberlee)(Frederick,Ashleigh)(Garett,Ashlynn)(Gordon,Krystal)(Grady,Vivian)(Graham,Berenice)(Hugo,Cheyenne)(Irving,Brandi)(Jacoby,Jami)(Jamar,Nicolette)(Jeremy,Sade)(Jordan,Aurora)(Juan,Leanne)(Kane,Miracle)(Keenan,Jerrica)(Lester,Aimee)(Madison,Whitley)(Marshall,Angie)(Melvin,Krista)(Moshe,Amani)(Nathanial,Monika)(Nico,Elsa)(Nicolas,Elaina)(Rocky,Beth)(Roderick,Kasandra)(Shelby,Lexus)(Skylar,Kallie)(Stephan,Shania)(Steve,Marlena)(Stewart,Rita)(Ulysses,Sofia)(Walter,Jaime)
6448
```
65-
MD5 of that ( Our flag):
49+
50+
MD5 of that \( Our flag\):
51+
6652
```
6753
51cacb0258b7862d646964c0da7c6125
6854
```
6955

7056
### External Writeups
7157

72-
* [https://github.com/ValarDragon/CTF-Writeups/blob/master/2017/EasyCTF/Match%20me/README.md](https://github.com/ValarDragon/CTF-Writeups/blob/master/2017/EasyCTF/Match%20me/README.md)
58+
* [https://github.com/ValarDragon/CTF-Writeups/blob/master/2017/EasyCTF/Match%20me/README.md](https://github.com/ValarDragon/CTF-Writeups/blob/master/2017/EasyCTF/Match me/README.md)
59+
60+
61+

0 commit comments

Comments
 (0)