-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can the code for the Algorithm quiz be attached in a separate txt file #2
Labels
Comments
Please give the link which code you want ? |
… On Thu, Jun 4, 2020, 11:33 PM Chanchal Kumar Maji ***@***.***> wrote:
Please give the link which code you want ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMHBWRXALEUY2FVNYFXRLI3RU7OWTANCNFSM4NS2BJBA>
.
|
def stableMatching(n, menPreferences, womenPreferences):
# Do not change the function definition line.
# Initially, all n men are unmarried
unmarriedMen = list(range(n))
# None of the men has a spouse yet, we denote this by the value None
manSpouse = [None] * n
# None of the women has a spouse yet, we denote this by the value None
womanSpouse = [None] * n
# Each man made 0 proposals, which means that
# his next proposal will be to the woman number 0 in his list
nextManChoice = [0] * n
# While there exists at least one unmarried man:
while unmarriedMen:
# Pick an arbitrary unmarried man
he = unmarriedMen[0]
# Store his ranking in this variable for convenience
hisPreferences = menPreferences[he]
# Find a woman to propose to
she = hisPreferences[0]
# Store her ranking in this variable for convenience
herPreferences = womenPreferences[she]
# Find the present husband of the selected woman (it might be None)
#currentHusband = womanSpouse[she]
# Write your code here
# Now "he" proposes to "she".
# Decide whether "she" accepts, and update the following fields
# 1. manSpouse
# 2. womanSpouse
# 3. unmarriedMen
# 4. nextManChoice
if he in herPreferences:
manSpouse[he] = she
if womanSpouse[she] != None:
manSpouse[womanSpouse[she]] = None
unmarriedMen.append(womanSpouse[she])
womanSpouse[she] = he
l = []
for e in herPreferences:
if e == he:
womenPreferences[she] = l
break
else:
l.append(e)
unmarriedMen.remove(he)
menPreferences[he].remove(she)
# Note that if you don't update the unmarriedMen list,
# then this algorithm will run forever.
# Thus, if you submit this default implementation,
# you may receive "SUBMIT ERROR".
return manSpouse
# You might want to test your implementation on the following two tests:
# assert(stableMatching(1, [ [0] ], [ [0] ]) == [0])
# assert(stableMatching(2, [ [0,1], [1,0] ], [ [0,1], [1,0] ]) == [0, 1]) |
Hello. Did you have the pdf of the book that was in the specialization? Can you upload it? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: