Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -2,7 +2,7 @@ import std.stdio, std.array, std.algorithm, std.string;
|
|||
|
||||
|
||||
string[string] matchmaker(string[][string] guyPrefers,
|
||||
string[][string] girlPrefers) {
|
||||
string[][string] girlPrefers) /*@safe*/ {
|
||||
string[string] engagedTo;
|
||||
string[] freeGuys = guyPrefers.keys;
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ string[string] matchmaker(string[][string] guyPrefers,
|
|||
|
||||
bool check(bool doPrint=false)(string[string] engagedTo,
|
||||
string[][string] guyPrefers,
|
||||
string[][string] galPrefers) {
|
||||
string[][string] galPrefers) @safe {
|
||||
enum MSG = "%s likes %s better than %s and %s " ~
|
||||
"likes %s better than their current partner";
|
||||
string[string] inverseEngaged;
|
||||
|
|
@ -77,7 +77,7 @@ bool check(bool doPrint=false)(string[string] engagedTo,
|
|||
}
|
||||
|
||||
|
||||
void main() {
|
||||
void main() /*@safe*/ {
|
||||
auto guyData = "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
|
||||
|
|
@ -111,7 +111,7 @@ void main() {
|
|||
|
||||
writeln("\nCouples:");
|
||||
string[] parts;
|
||||
foreach (k; engagedTo.keys.sort)
|
||||
foreach (k; engagedTo.keys.sort())
|
||||
writefln("%s is engagedTo to %s", k, engagedTo[k]);
|
||||
writeln();
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ void main() {
|
|||
writeln("Marriages are ", c ? "stable" : "unstable");
|
||||
|
||||
writeln("\n\nSwapping two fiances to introduce an error");
|
||||
auto gals = galPrefers.keys.sort;
|
||||
auto gals = galPrefers.keys.sort();
|
||||
swap(engagedTo[gals[0]], engagedTo[gals[1]]);
|
||||
foreach (gal; gals[0 .. 2])
|
||||
writefln(" %s is now engagedTo to %s", gal, engagedTo[gal]);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ alias Couples = M[F];
|
|||
immutable PrefMapF womenPref;
|
||||
immutable PrefMapM menPref;
|
||||
|
||||
pure nothrow static this() {
|
||||
static this() pure nothrow @safe {
|
||||
with (F) with (M) {
|
||||
womenPref = [
|
||||
abi: [bob, fred, jon, gav, ian, abe, dan, ed, col, hal],
|
||||
|
|
@ -42,13 +42,15 @@ pure nothrow static this() {
|
|||
|
||||
/// Does 'first' appear before 'second' in preference list?
|
||||
bool prefers(T)(in T[] preference, in T first, in T second)
|
||||
pure nothrow if (is(T == F) || is(T == M)) {
|
||||
const found = preference.findAmong([first, second]);
|
||||
pure nothrow @safe @nogc if (is(T == F) || is(T == M)) {
|
||||
//const found = preference.findAmong([first, second]);
|
||||
immutable T[2] two = [first, second];
|
||||
const found = preference.findAmong(two[]);
|
||||
return !(found.empty || found.front == second);
|
||||
}
|
||||
|
||||
void checkStability(in Couples engaged, in PrefMapM menPref,
|
||||
in PrefMapF womenPref) {
|
||||
in PrefMapF womenPref) @safe {
|
||||
"Stablility:".writeln;
|
||||
bool stable = true;
|
||||
foreach (immutable bride, immutable groom; engaged) {
|
||||
|
|
@ -74,7 +76,7 @@ void checkStability(in Couples engaged, in PrefMapM menPref,
|
|||
"\t(all marriages stable)".writeln;
|
||||
}
|
||||
|
||||
void main() {
|
||||
void main() /*@safe*/ {
|
||||
auto bachelors = menPref.keys.sort().release;// No queue in Phobos.
|
||||
Couples engaged;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue