Stable marriage problem: Difference between revisions

m
J: added whitespace to allow some syntax highlighting
(J Implementation)
m (J: added whitespace to allow some syntax highlighting)
Line 374:
'engaged etc'=.x
'male feml'=.y
if. feml e. engaged do.
pref=.feml{fpref
fiance=. engaged i.feml
Line 387:
 
GaleShap=:3 :0
whilst. _ e.{.y do.
for_guy. I._={.y do.
ctrl=. <1,guy
next=. ctrl{y
Line 406:
fhappy=. satisfied (gal{fpref) i."1 0/ guy
stable=. mhappy+.|:fhappy
if. bad=.0 e.,stable do.
smoutput 'Better matches:'
smoutput ((guy{male),:(gal{feml)){~"1 0"2 1($stable)#:I.,-.stable
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.
 
 
=={{header|Java}}==
6,962

edits