注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
本帖最后由 匿名 于 2022-2-17 11:23 编辑
新手求米
#
# Your previous Plain Text content is preserved below:
#
# Step 1
# Imagine an Airbnb-like vacation rental service, where users in different cities can exchange their apartment with another user for a week. Each user compiles a wishlist of the apartments they like. These wishlists are ordered, so the top apartment on a wishlist is that user's first choice for where they would like to spend a vacation. You will be asked to write part of the code that will help an algorithm find pairs of users who would like to swap with each other.
#
# Given a set of users, each with an *ordered* wishlist of other users' apartments:
#
# a's wishlist: c d
# b's wishlist: d a c
# c's wishlist: a b
# d's wishlist: c a b
#
# The first user in each wishlist is the user's first-choice for whose apartment they would like to swap into.
# Write a function called has_mutual_first_choice() which takes a username and returns true if that user and another user are each other's first choice, and otherwise returns false.
#
# has_mutual_first_choicresult of the change. Note that, as before, the
# username and rank passed in identify the entry whose rank is being bumped up, so (a, 1) would refer to a's second-choice.
#
# // if b's third choice becomes their second choice, b and c will no longer be a mutually-ranked anti-pairing
# changed_antipairings('b', 2) // returns ['c']
#
# // if a's second choice becomes their first choice, a and c will be no longer be a mutually ranked anti-pairing
# // in addition, a and d will become a mutually ranked anti-pairing (the second-to-last choice of each other)
# changed_antipairings('a', 1) // returns ['c', 'd']
|