Stable marriage problem: Difference between revisions

Content added Content deleted
Line 7,346: Line 7,346:
{{trans|PicoLisp}}
{{trans|PicoLisp}}
<lang zkl>var
<lang zkl>var
Boys=D(
Boys=Dictionary(
"abe", "abi eve cath ivy jan dee fay bea hope gay".split(),
"abe", "abi eve cath ivy jan dee fay bea hope gay".split(),
"bob", "cath hope abi dee eve fay bea jan ivy gay".split(),
"bob", "cath hope abi dee eve fay bea jan ivy gay".split(),
Line 7,357: Line 7,357:
"ian", "hope cath dee gay bea abi fay ivy jan eve".split(),
"ian", "hope cath dee gay bea abi fay ivy jan eve".split(),
"jon", "abi fay jan gay eve bea dee cath ivy hope".split(), ),
"jon", "abi fay jan gay eve bea dee cath ivy hope".split(), ),
Girls=D(
Girls=Dictionary(
"abi", "bob fred jon gav ian abe dan ed col hal".split(),
"abi", "bob fred jon gav ian abe dan ed col hal".split(),
"bea", "bob abe col fred gav dan ian ed jon hal".split(),
"bea", "bob abe col fred gav dan ian ed jon hal".split(),
Line 7,370: Line 7,370:
Couples=List(); // ( (boy,girl),(boy,girl),...)
Couples=List(); // ( (boy,girl),(boy,girl),...)
Boyz:=Boys.pump(D(),fcn([(b,gs)]){ return(b,gs.copy()) }); // make writable copy
Boyz:=Boys.pump(Dictionary(),fcn([(b,gs)]){ return(b,gs.copy()) }); // make writable copy
while( bgs:=Boyz.filter1( 'wrap([(Boy,gs)]){ // while unattached boy
while( bgs:=Boyz.filter1( 'wrap([(Boy,gs)]){ // while unattached boy
gs and (not Couples.filter1("holds",Boy))
gs and (not Couples.filter1("holds",Boy))