Dinesman's multiple-dwelling problem: Difference between revisions

Content added Content deleted
Line 1,336: Line 1,336:


===Simpler Version===
===Simpler Version===
<syntaxhighlight lang="d">void main() {
<syntaxhighlight lang="d">
void main() {
import std.stdio, std.math, std.algorithm, permutations2;
import std.stdio, std.math, std.algorithm, permutations2:permutations;


["Baker", "Cooper", "Fletcher", "Miller", "Smith"]
["Baker", "Cooper", "Fletcher", "Miller", "Smith"]
.permutations
.permutations
.filter!(s =>
.filter!(s =>
s.countUntil("Baker") != 4 && s.countUntil("Cooper") &&
s.countUntil("Baker") != 4 && s.countUntil("Cooper") != 0 &&
s.countUntil("Fletcher") && s.countUntil("Fletcher") != 4 &&
s.countUntil("Fletcher") != 0 && s.countUntil("Fletcher") != 4 &&
s.countUntil("Miller") > s.countUntil("Cooper") &&
s.countUntil("Miller") > s.countUntil("Cooper") &&
abs(s.countUntil("Smith") - s.countUntil("Fletcher")) != 1 &&
abs(s.countUntil("Smith") - s.countUntil("Fletcher")) != 1 &&
abs(s.countUntil("Cooper") - s.countUntil("Fletcher")) != 1)
abs(s.countUntil("Cooper") - s.countUntil("Fletcher")) != 1)
.writeln;
.writeln;
}</syntaxhighlight>
}</syntaxhighlight>

The output is the same.
The output is the same.