Dinesman's multiple-dwelling problem: Difference between revisions
Content added Content deleted
Line 1,304:
=={{header|D}}==
This code uses the second lazy permutations function of '''[[Permutations#Lazy_version]]'''.
As for flexibility: the solve code works with an arbitrary number of people and predicates.
<syntaxhighlight lang="d">
import std.stdio, std.math, std.algorithm, std.traits, std.array, permutations2:permutations;
void main() {
enum Names { Baker, Cooper, Fletcher, Miller, Smith }
immutable(bool function(in Names[]) pure nothrow)[] predicates = [
s => s.countUntil(Names.Fletcher) != 4
];
permutations([EnumMembers!Names]).filter!(solution => predicates.all!(pred => pred(solution)))
.writeln;
}</syntaxhighlight>
{{out}}
|