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): LinkedListList<String> {
val likesBetter = LinkedList<String>()
val prefers = get(k)!!
likesBetter.addAllreturn ArrayList<String>(prefers.slice(0..prefers.indexOf(v)))
return likesBetter
}
}
Line 3,291 ⟶ 3,289:
class EngagementRegistry() : TreeMap<String, String>() {
constructor(guys: People, girls: People) : this() {
val freeGuys = guys.names.toArrayListtoMutableList()
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 checkStabilityanalyse(guys: People, girls: People) {
if (check(guys, girls))
println("Marriages are stable")
Line 3,393 ⟶ 3,391:
val matches = EngagementRegistry(guys, girls)
print(matches)
matches.checkStabilityanalyse(guys, girls)
matches.swap(girls, 0, 1)
matches.checkStabilityanalyse(guys, girls)
}</lang>
{{out}}
Anonymous user