Stable marriage problem: Difference between revisions

Content added Content deleted
(Kotlin: with block idiom)
m (→‎{{header|Perl 6}}: usage of two hashes updated)
Line 4,050: Line 4,050:
</pre>
</pre>
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{Works with|rakudo|2016.10}}
{{trans|Perl}}
{{trans|Perl}}
<lang perl6>my %he-likes =
<lang perl6>my %he-likes =
Line 4,077: Line 4,078:
;
;


my \guys = %he-likes.keys;
my \gals = %she-likes.keys;
my %fiancé;
my %fiancé;
my %fiancée;
my %fiancée;
Line 4,112: Line 4,110:
sub check-stability {
sub check-stability {
my @instabilities = gather for guys X gals -> $m, $w {
my @instabilities = gather for flat %he-likes.keys X %she-likes.keys -> $m, $w {
if he-prefers($m, $w) and she-prefers($w, $m) {
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}";
take "\t$w prefers $m to %fiancé{$w} and $m prefers $w to %fiancée{$m}";
Line 4,127: Line 4,125:
}
}
sub unmatched-guy { guys.first: { not %fiancée{$_} } }
sub unmatched-guy { %he-likes.keys.first: { not %fiancée{$_} } }
sub preferred-choice($guy) { %he-likes{$guy}.first: { not %proposed{"$guy $_" } } }
sub preferred-choice($guy) { %he-likes{$guy}.first: { not %proposed{"$guy $_" } } }
Line 4,144: Line 4,142:
{{out}}
{{out}}
<pre>Matchmaking:
<pre>Matchmaking:
abi and abe
cath and bob
cath and bob
ivy and dan
hope and col
abi and jon
ivy and dan
hope and ian
jan and ed
jan and ed
bea and fred
eve and abe
eve dumped abe for hal
gay and gav
ivy dumped dan for abe
eve and hal
fay and dan
hope dumped col for ian
dee and col
gay and gav
bea and fred
abi dumped abe for jon
dee and col
ivy dumped dan for abe
fay and dan
Stablility:
Stablility:
(all marriages stable)
(all marriages stable)
Perturb:
Perturb:
engage abi with fred and bea with jon
engage abi with fred and bea with jon
Stablility:
Stablility:
bea prefers fred to jon and fred prefers bea to abi
fay prefers jon to dan and jon prefers fay to bea
eve prefers jon to hal and jon prefers eve to bea
eve prefers jon to hal and jon prefers eve to bea
fay prefers jon to dan and jon prefers fay to bea
gay prefers jon to gav and jon prefers gay to bea
gay prefers jon to gav and jon prefers gay to bea</pre>
bea prefers fred to jon and fred prefers bea to abi</pre>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==