Anonymous user
Stable marriage problem: Difference between revisions
Kotlin version updated
(Added EchoLisp) |
(Kotlin version updated) |
||
Line 3,281:
val names: List<String> by lazy { map.keys.toList() }
fun preferences(k: String, v: String):
val prefers = get(k)!!
}
}
Line 3,291 ⟶ 3,289:
class EngagementRegistry() : TreeMap<String, String>() {
constructor(guys: People, girls: People) : this() {
val freeGuys = guys.names.
while (freeGuys.any()) {
val guy = freeGuys.removeAt(0) // get a load of THIS guy
val guy_p = guys[guy]!!
for (girl in guy_p)
Line 3,317 ⟶ 3,315:
}
fun
if (check(guys, girls))
println("Marriages are stable")
Line 3,393 ⟶ 3,391:
val matches = EngagementRegistry(guys, girls)
print(matches)
matches.
matches.swap(girls, 0, 1)
matches.
}</lang>
{{out}}
|