Stable marriage problem: Difference between revisions

m
→‎{{header|Perl 6}}: usage of two hashes updated
(Kotlin: with block idiom)
m (→‎{{header|Perl 6}}: usage of two hashes updated)
Line 4,050:
</pre>
=={{header|Perl 6}}==
{{Works with|rakudo|2016.10}}
{{trans|Perl}}
<lang perl6>my %he-likes =
Line 4,077 ⟶ 4,078:
;
 
my \guys = %he-likes.keys;
my \gals = %she-likes.keys;
my %fiancé;
my %fiancée;
Line 4,112 ⟶ 4,110:
sub check-stability {
my @instabilities = gather for guysflat %he-likes.keys X gals%she-likes.keys -> $m, $w {
if he-prefers($m, $w) and she-prefers($w, $m) {
take "\t$w prefers $m to %fiancé{$w} and $m prefers $w to %fiancée{$m}";
Line 4,127 ⟶ 4,125:
}
sub unmatched-guy { guys%he-likes.keys.first: { not %fiancée{$_} } }
sub preferred-choice($guy) { %he-likes{$guy}.first: { not %proposed{"$guy $_" } } }
Line 4,144 ⟶ 4,142:
{{out}}
<pre>Matchmaking:
abi cath and abebob
cath ivy and bobdan
hope abi and coljon
ivy hope and danian
jan and ed
bea eve and fredabe
abi eve dumped abe for jonhal
gay and gav
ivy dumped dan for abe
eve and hal
fay and dan
hope dumped col for ian
dee gay and colgav
bea and fred
abi dumped abe for jon
dee and col
ivy dumped dan for abe
fay and dan
Stablility:
(all marriages stable)
Perturb:
engage abi with fred and bea with jon
Stablility:
bea fay prefers fredjon to jondan and fredjon prefers beafay to abibea
eve prefers jon to hal and jon prefers eve to bea
fay gay prefers jon to dangav and jon prefers faygay to bea
gay bea prefers jonfred to gavjon and jonfred prefers gaybea to beaabi</pre>
 
=={{header|PicoLisp}}==
2,392

edits