Jump to content

Stable marriage problem: Difference between revisions

m
syntax highlighting fixup automation
(Added 11l)
m (syntax highlighting fixup automation)
Line 56:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V guyprefers = [‘abe’ = [‘abi’, ‘eve’, ‘cath’, ‘ivy’, ‘jan’, ‘dee’, ‘fay’, ‘bea’, ‘hope’, ‘gay’],
‘bob’ = [‘cath’, ‘hope’, ‘abi’, ‘dee’, ‘eve’, ‘fay’, ‘bea’, ‘jan’, ‘ivy’, ‘gay’],
‘col’ = [‘hope’, ‘eve’, ‘abi’, ‘dee’, ‘bea’, ‘fay’, ‘ivy’, ‘gay’, ‘cath’, ‘jan’],
Line 139:
print(‘ #. is now engaged to #.’.format(gal, engaged[gal]))
print()
print(I check(engaged) {‘Engagement stability check PASSED’} E ‘Engagement stability check FAILED’)</langsyntaxhighlight>
 
{{out}}
Line 184:
=={{header|AutoHotkey}}==
{{works with|AutoHotkey L}}
<langsyntaxhighlight lang="autohotkey">; Given a complete list of ranked preferences, where the most liked is to the left:
abe := ["abi", "eve", "cath", "ivy", "jan", "dee", "fay", "bea", "hope", "gay"]
bob := ["cath", "hope", "abi", "dee", "eve", "fay", "bea", "jan", "ivy", "gay"]
Line 272:
Else
Return "`nThese couples are stable.`n"
}</langsyntaxhighlight>
{{out}}
<pre>Engagements:
Line 328:
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">:: Stable Marriage Problem in Rosetta Code
:: Batch File Implementation
 
Line 475:
set "!%~1.tmp!_=%~2"
set "!%~2.tmp!_=%~1"
goto :EOF</langsyntaxhighlight>
{{Out}}
<pre>HISTORY:
Line 528:
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> N = 10
DIM mname$(N), wname$(N), mpref$(N), wpref$(N), mpartner%(N), wpartner%(N)
DIM proposed&(N,N)
Line 595:
NEXT o%
NEXT m%
= TRUE</langsyntaxhighlight>
'''Output:'''
<pre>
Line 617:
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat">( (abe.abi eve cath ivy jan dee fay bea hope gay)
(bob.cath hope abi dee eve fay bea jan ivy gay)
(col.hope eve abi dee bea fay ivy gay cath jan)
Line 682:
| out$stable
)
);</langsyntaxhighlight>
{{out}}
<pre>stable
Line 700:
=={{header|C}}==
Oddly enough (or maybe it should be that way, only that I don't know): if the women were proposing instead of the men, the resulting pairs are exactly the same.
<langsyntaxhighlight Clang="c">#include <stdio.h>
 
int verbose = 0;
Line 833:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Pairing:
Line 859:
=={{header|C sharp|C#}}==
(This is a straight-up translation of the Objective-C version.)
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
 
Line 983:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,002:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <iostream>
#include <map>
Line 1,142:
 
check_stability(engaged, men_pref, women_pref);
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,182:
 
=={{header|Ceylon}}==
<langsyntaxhighlight lang="ceylon">abstract class Single(name) of Gal | Guy {
 
shared String name;
Line 1,319:
}
print("``if(!stabilityFlag) then "Not " else ""``Stable!");
}</langsyntaxhighlight>
{{out}}
<pre>------ the matchmaking process ------
Line 1,360:
 
=={{header|CoffeeScript}}==
<langsyntaxhighlight lang="coffeescript">class Person
constructor: (@name, @preferences) ->
@mate = null
Line 1,487:
perturb guys
report_on_mates guys
report_potential_adulteries guys</langsyntaxhighlight>
{{out}}
<pre>
Line 1,543:
 
=={{header|ColdFusion}}==
<langsyntaxhighlight lang="cfm">
PERSON.CFC
 
Line 1,665:
}
}
</syntaxhighlight>
</lang>
<langsyntaxhighlight lang="cfm">
INDEX.CFM
 
Line 1,780:
}
</cfscript>
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,850:
=={{header|D}}==
From the Python and Java versions:
<langsyntaxhighlight lang="d">import std.stdio, std.array, std.algorithm, std.string;
 
 
Line 1,979:
c = check!(true)(engagedTo, guyPrefers, galPrefers);
writeln("Marriages are ", c ? "stable" : "unstable");
}</langsyntaxhighlight>
{{out}}
<pre>Engagements:
Line 2,005:
Marriages are unstable</pre>
===Stronger Version===
<langsyntaxhighlight lang="d">import std.stdio, std.algorithm, std.array;
 
enum F { abi, bea, cath, dee, eve, fay, gay, hope, ivy, jan }
Line 2,124:
checkStability(engaged, menPref, womenPref);
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Matchmaking:
Line 2,162:
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
(lib 'hash)
;; input data
Line 2,237:
(error 'not-stable (list man woman)))))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,274:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">let menPrefs =
Map.ofList
["abe", ["abi";"eve";"cath";"ivy";"jan";"dee";"fay";"bea";"hope";"gay"];
Line 2,420:
husbandOf = solution.husbandOf.Add( gal0, guy1 ).Add( gal1, guy0 ) }
 
printfn "Perturbed is stable: %A" (isStable perturbed)</langsyntaxhighlight>
{{out}}
<pre>
Line 2,438:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 2,641:
fmt.Println("stable.")
return true
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,695:
 
"Stable Matching" Solution:
<langsyntaxhighlight lang="groovy">import static Man.*
import static Woman.*
 
Line 2,720:
}
engagedTo
}</langsyntaxhighlight>
 
"Stability Checking" Solution:
(Could do more to eliminate common code. Maybe later.)
<langsyntaxhighlight lang="groovy">boolean isStable(Map<Woman,Man> matches, Map<Man,Map<Woman,Integer>> guysGalRanking, Map<Woman,Map<Man,Integer>> galsGuyRanking) {
matches.collect{ girl, guy ->
int guysRank = galsGuyRanking[girl][guy]
Line 2,749:
true
}.every()
}</langsyntaxhighlight>
 
Test (Stable and Perturbed):
<langsyntaxhighlight lang="groovy">enum Man {
abe, bob, col, dan, ed, fred, gav, hal, ian, jon
}
Line 2,807:
println ''
 
assert ! isStable(matches, mansWomanRanking, womansManRanking)</langsyntaxhighlight>
{{out}}
<pre>abi (his '10' girl) is engaged to jon (her '8' guy)
Line 2,852:
The state here consists of the list of free guys and associative preferences lists for guys and girls correspondingly. In order to simplify the access to elements of the state we use lenses.
 
<langsyntaxhighlight lang="haskell">{-# LANGUAGE TemplateHaskell #-}
import Lens.Micro
import Lens.Micro.TH
Line 2,863:
, _girls :: [Preferences a]}
 
makeLenses ''State</langsyntaxhighlight>
 
Lenses allow us to get access to each person in the state, and even to the associated preference list:
 
<langsyntaxhighlight Haskelllang="haskell">name n = lens get set
where get = head . dropWhile ((/= n).fst)
set assoc (_,v) = let (prev, _:post) = break ((== n).fst) assoc
Line 2,873:
 
fianceesOf n = guys.name n._2
fiancesOf n = girls.name n._2</langsyntaxhighlight>
 
Note that in following we use lens operators:
Line 2,885:
With these tools and notes we are ready to implement the Gale/Shapley algorithm and the stability test as they are given in a textbook:
 
<langsyntaxhighlight Haskelllang="haskell">stableMatching :: Eq a => State a -> [Couple a]
stableMatching = getPairs . until (null._freeGuys) step
where
Line 2,915:
, elemIndex w2 fm < elemIndex w1 fm
, let fw = s^.fiancesOf w2
, elemIndex m2 fw < elemIndex m1 fw ]</langsyntaxhighlight>
 
This solution works not only for strings, but for any equable data.
Line 2,923:
Here are the given preferences:
 
<langsyntaxhighlight Haskelllang="haskell">guys0 =
[("abe", ["abi", "eve", "cath", "ivy", "jan", "dee", "fay", "bea", "hope", "gay"]),
("bob", ["cath", "hope", "abi", "dee", "eve", "fay", "bea", "jan", "ivy", "gay"]),
Line 2,945:
("hope", ["gav", "jon", "bob", "abe", "ian", "dan", "hal", "ed", "col", "fred"]),
("ivy", ["ian", "col", "hal", "gav", "fred", "bob", "abe", "ed", "jon", "dan"]),
("jan", ["ed", "hal", "gav", "abe", "bob", "jon", "col", "ian", "fred", "dan"])]</langsyntaxhighlight>
The initial state:
 
<langsyntaxhighlight Haskelllang="haskell">s0 = State (fst <$> guys0) guys0 ((_2 %~ reverse) <$> girls0)</langsyntaxhighlight>
 
And the solution:
Line 2,979:
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">link printf
 
procedure main()
Line 3,091:
return X
end</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 3,143:
 
=={{header|J}}==
<langsyntaxhighlight lang="j">Mraw=: ;: ;._2 noun define -. ':,'
abe: abi, eve, cath, ivy, jan, dee, fay, bea, hope, gay
bob: cath, hope, abi, dee, eve, fay, bea, jan, ivy, gay
Line 3,214:
end.
assert-.bad
)</langsyntaxhighlight>
 
For most of this, males and females are both represented by indices. Rows of <code>Mprefs</code> are indexed by a male index and each contains a list female indices, in priority order. Rows of <code>Fprefs</code> are indexed by a female index and each contains a list male indices in priority order. These indices select the corresponding names from <code>GuyNames</code> and <code>GalNames</code>.
Line 3,222:
Example use:
 
<langsyntaxhighlight lang="j"> matchMake ''
┌───┬────┬───┬───┬───┬────┬───┬───┬────┬───┐
│abe│bob │col│dan│ed │fred│gav│hal│ian │jon│
├───┼────┼───┼───┼───┼────┼───┼───┼────┼───┤
│ivy│cath│dee│fay│jan│bea │gay│eve│hope│abi│
└───┴────┴───┴───┴───┴────┴───┴───┴────┴───┘</langsyntaxhighlight>
 
Stability check:
 
<langsyntaxhighlight lang="j"> checkStable matchMake''
</langsyntaxhighlight>
 
(no news is good news)
Line 3,238:
An altered result, and a stability check on it (showing what would happen for a bogus result):
 
<langsyntaxhighlight lang="j"> 0 105 A."_1 matchMake '' NB. swap abi and bea
┌───┬────┬───┬───┬───┬────┬───┬───┬────┬───┐
│abe│bob │col│dan│ed │fred│gav│hal│ian │jon│
Line 3,256:
└────┴───┘
|assertion failure: assert
| assert-.bad</langsyntaxhighlight>
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 match for any guy was fourth preference where the worst for any gal was seventh preference.
 
=={{header|Java}}==
This is not a direct translation of [[#Python|Python]], but it's fairly close (especially the stability check).
<langsyntaxhighlight lang="java5">import java.util.*;
 
public class Stable {
Line 3,440:
return true;
}
}</langsyntaxhighlight>
{{out}}
<pre>abi is engaged to jon
Line 3,458:
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">function Person(name) {
 
var candidateIndex = 0;
Line 3,579:
 
doMarriage();
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,597:
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
# This is not optimized, but tries to follow the pseudocode given the Wikipedia entry below.
# Reference: https://en.wikipedia.org/wiki/Stable_marriage_problem#Algorithm
Line 3,724:
tableprint("Original Data With Bob and Abe Switched", answer[1], stabl)
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,784:
=={{header|Kotlin}}==
 
<langsyntaxhighlight lang="java">
data class Person(val name: String) {
val preferences = mutableListOf<Person>()
Line 3,891:
println("#### match is stable: ${isStableMatch(males, females)}")
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,922:
{{trans|C#}}
 
<langsyntaxhighlight lang="lua">local Person = {}
Person.__index = Person
 
Line 4,050:
jon.fiance, fred.fiance = fred.fiance, jon.fiance
print('Stable: ', isStable(men))
</syntaxhighlight>
</lang>
 
{{out}}
Line 4,074:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica"><<Combinatorica`;
ClearAll[CheckStability]
CheckStabilityHelp[male_, female_, ml_List, fl_List, pairing_List] := Module[{prefs, currentmale},
Line 4,125:
pairing[[{2, 7}, 2]] //= Reverse;
pairing
CheckStability[ml, fl, pairing]</langsyntaxhighlight>
{{out}}
<pre>{{1,9},{2,3},{3,4},{4,6},{5,10},{6,2},{7,7},{8,5},{9,8},{10,1}}
Line 4,133:
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import sequtils, random, strutils
 
const
Line 4,250:
echo "Current pair analysis:"
discard checkPairStability(contPairs, recPairs)
</syntaxhighlight>
</lang>
{{out}}
<pre>abe 💑 ivy
Line 4,283:
{{Works with|XCode 4.5.1}}
(The C# version is essentially the same as this.)
<langsyntaxhighlight lang="objc">//--------------------------------------------------------------------
// Person class
 
Line 4,419:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 4,438:
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">let men = [
"abe", ["abi";"eve";"cath";"ivy";"jan";"dee";"fay";"bea";"hope";"gay"];
"bob", ["cath";"hope";"abi";"dee";"eve";"fay";"bea";"jan";"ivy";"gay"];
Line 4,595:
let engagements = perturb_engagements engagements in
print engagements;
;;</langsyntaxhighlight>
{{out}}
<pre> fay is engaged with dan
Line 4,622:
 
=={{header|Perl}}==
<langsyntaxhighlight Perllang="perl">#!/usr/bin/env perl
use strict;
use warnings;
Line 4,738:
 
sub men { keys %{ $Likes{M} } }
sub women { keys %{ $Likes{W} } }</langsyntaxhighlight>
{{out}}
<pre>
Line 4,769:
=={{header|Phix}}==
{{trans|AutoHotkey}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">men</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"abe"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"bob"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"col"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"dan"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ed"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"fred"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"gav"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"hal"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ian"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"jon"</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">enum</span> <span style="color: #000000;">abe</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">bob</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">col</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">dan</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">ed</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">fred</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">gav</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">hal</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">ian</span> <span style="color: #0000FF;">,</span> <span style="color: #000000;">jon</span>
Line 4,857:
<span style="color: #000000;">engagements</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cath</span><span style="color: #0000FF;">]:=</span><span style="color: #000000;">abe</span><span style="color: #0000FF;">;</span> <span style="color: #000000;">engagements</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ivy</span><span style="color: #0000FF;">]:=</span><span style="color: #000000;">bob</span>
<span style="color: #000000;">stable</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{Out}}
<pre>
Line 4,900:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(setq
*Boys (list
(de abe abi eve cath ivy jan dee fay bea hope gay)
Line 4,964:
(con (asoq 'fred *Couples) 'abi)
(con (asoq 'jon *Couples) 'bea)
(checkCouples)</langsyntaxhighlight>
{{out}}
<pre>dee is engaged to col
Line 4,987:
{{Works with|SWI-Prolog}}{{libheader|XPCE}}
XPCE is used for its integrated messaging system.
<langsyntaxhighlight Prologlang="prolog">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% facts
prefere(abe,[ abi, eve, cath, ivy, jan, dee, fay, bea, hope, gay]).
Line 5,260:
( (IY12 < IY11 , IX21 < IX22);
(IY21 < IY22 , IX12 < IX11)).
</syntaxhighlight>
</lang>
{{out}}
<pre> ?- stable_mariage.
Line 5,287:
true </pre>
A more Prolog-ish version (working with SWI-Prolog) could be :
<langsyntaxhighlight Prologlang="prolog">:- dynamic person/4, prop/2.
% person(Name, Preference, Status, Candidate)
% prop(Name, List_of_Candidates) (for a woman)
Line 5,500:
% A couple is unstable
( (IY12 < IY11 , IX21 < IX22);
(IY21 < IY22 , IX12 < IX11)).</langsyntaxhighlight>
 
=={{header|PureBasic}}==
This approach uses a messaging system to pass messages between prospective partners.
<langsyntaxhighlight PureBasiclang="purebasic">#coupleCount = 10
 
DataSection
Line 5,677:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
{{out}}
<pre>Marriages:
Line 5,705:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">import copy
 
guyprefers = {
Line 5,807:
print()
print('Engagement stability check PASSED'
if check(engaged) else 'Engagement stability check FAILED')</langsyntaxhighlight>
{{out}}
<pre>Engagements:
Line 5,847:
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
 
Line 5,933:
(swap! (hash-ref matches (car M)) (hash-ref matches (cadr M))))
(check-stability)
</syntaxhighlight>
</lang>
 
Sample run:
Line 5,957:
{{Works with|rakudo|2016.10}}
{{trans|Perl}}
<syntaxhighlight lang="raku" perl6line>my %he-likes =
abe => < abi eve cath ivy jan dee fay bea hope gay >,
bob => < cath hope abi dee eve fay bea jan ivy gay >,
Line 6,044:
engage('fred', 'abi');
engage('jon', 'bea');
}</langsyntaxhighlight>
{{out}}
<pre>Matchmaking:
Line 6,071:
=={{header|REXX}}==
Algorithm used: see link https://www.youtube.com/watch?v=Qcv1IqHWAzg
<langsyntaxhighlight REXXlang="rexx">/*- REXX --------------------------------------------------------------
* pref.b Preferences of boy b
* pref.g Preferences of girl g
Line 6,275:
s=left(s,p-1)||new||substr(s,p+length(old))
End
Return s </langsyntaxhighlight>
{{out}}
<pre>
Line 6,301:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">class Person
def initialize(name)
@name = name
Line 6,471:
 
@men.each_value.collect {|man| puts "#{man} + #{man.fiance}"}
stability @men</langsyntaxhighlight>
{{out}}
<pre>abe + ivy
Line 6,507:
=={{header|Scala}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">object SMP extends App {
private def checkMarriages(): Unit =
if (check)
Line 6,613:
swap()
checkMarriages()
}</langsyntaxhighlight>
{{out}}
See Java output.
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const type: preferences is hash [string] array string;
Line 6,767:
writeln;
writeln("Marriages are " <& [] ("unstable", "stable") [succ(ord(check(engagedTo, guyPrefers, girlPrefers)))]);
end func;</langsyntaxhighlight>
 
Output:
Line 6,809:
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">var he_likes = Hash(
abe => < abi eve cath ivy jan dee fay bea hope gay >,
bob => < cath hope abi dee eve fay bea jan ivy gay >,
Line 6,897:
 
perturb_em();
check_stability();</langsyntaxhighlight>
{{out}}
<pre>
Line 6,929:
 
The data set package:
<langsyntaxhighlight lang="ada">package Preferences
is
 
Line 6,972:
 
end Preferences;
</syntaxhighlight>
</lang>
The package for creating the engagements and checking stability. This package can be analysed by the SPARK tools and proved to be free of any run-time error.
<langsyntaxhighlight lang="ada">with Preferences;
--# inherit Preferences;
package Propose
Line 6,993:
 
end Propose;
</syntaxhighlight>
</lang>
<langsyntaxhighlight lang="ada">with Preferences;
use type Preferences.Extended_Rank;
use type Preferences.Girl;
Line 7,132:
 
end Propose;
</syntaxhighlight>
</lang>
The test program tests all pairwise exchanges. This is Ada, it is not SPARK.
 
(Text IO is quite tedious in SPARK - it's not what the language was designed for.)
<langsyntaxhighlight lang="ada">------------------------------------
-- Test program.
--
Line 7,202:
 
end MatchMaker;
</syntaxhighlight>
</lang>
The begining of the output from the test. All pairwise exchanges create unstable pairings.
<pre>ABI marries JON
Line 7,228:
=={{header|Swift}}==
{{trans|JavaScript}}
<langsyntaxhighlight Swiftlang="swift">class Person {
let name:String
var candidateIndex = 0
Line 7,365:
}
 
doMarriage()</langsyntaxhighlight>
{{out}}
<pre>
Line 7,384:
=={{header|Tcl}}==
{{trans|Python}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
 
# Functions as aliases to standard commands
Line 7,499:
}
puts ""
puts "Engagement stability check [lindex {FAILED PASSED} [check $engaged]]"</langsyntaxhighlight>
{{out}}
<pre>
Line 7,543:
{{works with|Bourne Again Shell|4.0}}
{{trans|AutoHotkey}}
<langsyntaxhighlight lang="shell">#!/usr/bin/env bash
main() {
# Our ten males:
Line 7,709:
}
 
main "$@"</langsyntaxhighlight>
{{Out}}
<pre>abi accepted abe
Line 7,766:
 
=={{header|Ursala}}==
<langsyntaxhighlight Ursalalang="ursala">men =
 
{
Line 7,813:
'stable': match/men women,
'perturbed': ~&lSrSxPp match/men women,
'preferred': preferred/(men,women) ~&lSrSxPp match/men women></langsyntaxhighlight>
The matches are perturbed by reversing the order of the women.
{{out}}
Line 7,873:
 
'''The string approach'''<br/>
<langsyntaxhighlight lang="vb">Sub M_snb()
c00 = "_abe abi eve cath ivy jan dee fay bea hope gay " & _
"_bob cath hope abi dee eve fay bea jan ivy gay " & _
Line 7,916:
MsgBox Replace(Join(Filter(Split(c00), "-"), vbLf), "_", "")
End Sub</langsyntaxhighlight>
 
'''The Dictionary approach'''
 
<langsyntaxhighlight lang="vb">Sub M_snb()
Set d_00 = CreateObject("scripting.dictionary")
Set d_01 = CreateObject("scripting.dictionary")
Line 7,975:
MsgBox Join(d_00.items, vbLf)
End Sub</langsyntaxhighlight>
 
{{out}}
Line 7,995:
{{libheader|Wren-dynamic}}
Although this is a faithful translation, the results are not identical to those of Go as map iteration order in both languages is undefined.
<langsyntaxhighlight lang="ecmascript">import "/dynamic" for Struct
 
var mPref = {
Line 8,165:
if (!validateStable.call(ps, mPref, wPref)) return
// if those happened to be stable as well, perturb more
}</langsyntaxhighlight>
 
{{out}}
Line 8,222:
Assume that the input is in XML form as listed [[Stable marriage problem/XSLT input|here]]. The following XSLT 2.0 style-sheet...
 
<syntaxhighlight lang="text"><xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
Line 8,357:
</xsl:function>
</xsl:stylesheet></langsyntaxhighlight>
 
...when applied to the said input document will yield...
 
<syntaxhighlight lang="text"><t>
<m:stable-marriage-problem-result xmlns:m="http://rosettacode.org/wiki/Stable_marriage_problem">
<m:solution is-stable="true">
Line 8,408:
<m:message>The perturbed configuration is unstable.</m:message>
</m:stable-marriage-problem-result>
</t></langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|PicoLisp}}
<langsyntaxhighlight lang="zkl">var
Boys=Dictionary(
"abe", "abi eve cath ivy jan dee fay bea hope gay".split(),
Line 8,473:
Couples.filter1("holds","fred")[1]="abi";
Couples.filter1("holds","jon") [1]="bea";
checkCouples(Couples);</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.