Stable marriage problem: Difference between revisions

Content added Content deleted
(J Implementation)
m (J: added whitespace to allow some syntax highlighting)
Line 374: Line 374:
'engaged etc'=.x
'engaged etc'=.x
'male feml'=.y
'male feml'=.y
if.feml e. engaged do.
if. feml e. engaged do.
pref=.feml{fpref
pref=.feml{fpref
fiance=. engaged i.feml
fiance=. engaged i.feml
Line 387: Line 387:


GaleShap=:3 :0
GaleShap=:3 :0
whilst._ e.{.y do.
whilst. _ e.{.y do.
for_guy.I._={.y do.
for_guy. I._={.y do.
ctrl=. <1,guy
ctrl=. <1,guy
next=. ctrl{y
next=. ctrl{y
Line 406: Line 406:
fhappy=. satisfied (gal{fpref) i."1 0/ guy
fhappy=. satisfied (gal{fpref) i."1 0/ guy
stable=. mhappy+.|:fhappy
stable=. mhappy+.|:fhappy
if.bad=.0 e.,stable do.
if. bad=.0 e.,stable do.
smoutput 'Better matches:'
smoutput 'Better matches:'
smoutput ((guy{male),:(gal{feml)){~"1 0"2 1($stable)#:I.,-.stable
smoutput ((guy{male),:(gal{feml)){~"1 0"2 1($stable)#:I.,-.stable
Line 446: Line 446:


As an aside, note that the guys fared much better than the gals here, with over half of the guys getting their first preference and only one gal getting her first preference. The worst matching for any guy was fourth preference where the worst for any gal was seventh preference.
As an aside, note that the guys fared much better than the gals here, with over half of the guys getting their first preference and only one gal getting her first preference. The worst matching for any guy was fourth preference where the worst for any gal was seventh preference.



=={{header|Java}}==
=={{header|Java}}==