Stable marriage problem: Difference between revisions
Content added Content deleted
(Kotlin: with block idiom) |
SqrtNegInf (talk | contribs) 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 |
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 { |
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: |
||
cath and bob |
|||
ivy and dan |
|||
abi and jon |
|||
hope and ian |
|||
jan and ed |
|||
eve and abe |
|||
⚫ | |||
gay and gav |
|||
⚫ | |||
eve and hal |
|||
⚫ | |||
hope dumped col for ian |
|||
gay and gav |
|||
bea and fred |
|||
⚫ | |||
dee and col |
|||
⚫ | |||
⚫ | |||
Stablility: |
Stablility: |
||
(all marriages stable) |
|||
Perturb: |
Perturb: |
||
engage abi with fred and bea with jon |
|||
Stablility: |
Stablility: |
||
fay prefers jon to dan and jon prefers fay to bea |
|||
eve prefers jon to hal and jon prefers eve to bea |
|||
gay prefers jon to gav and jon prefers gay to bea |
|||
bea prefers fred to jon and fred prefers bea to abi</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |