CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
|
|
@ -0,0 +1,17 @@
|
|||
import std.stdio, std.math, std.algorithm, std.traits, permutations2;
|
||||
|
||||
void main() {
|
||||
enum Names { Baker, Cooper, Fletcher, Miller, Smith }
|
||||
|
||||
immutable(bool function(in Names[]) pure nothrow)[] predicates = [
|
||||
s => s[Names.Baker] != s.length - 1,
|
||||
s => s[Names.Cooper] != 0,
|
||||
s => s[Names.Fletcher] != 0 && s[Names.Fletcher] != s.length-1,
|
||||
s => s[Names.Miller] > s[Names.Cooper],
|
||||
s => abs(s[Names.Smith] - s[Names.Fletcher]) != 1,
|
||||
s => abs(s[Names.Cooper] - s[Names.Fletcher]) != 1];
|
||||
|
||||
permutations([EnumMembers!Names])
|
||||
.filter!(solution => predicates.all!(pred => pred(solution)))
|
||||
.writeln;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import std.stdio, std.math, std.algorithm, permutations2;
|
||||
|
||||
void main() {
|
||||
["Baker", "Cooper", "Fletcher", "Miller", "Smith"]
|
||||
.permutations
|
||||
.filter!(s =>
|
||||
s.countUntil("Baker") != 4 && s.countUntil("Cooper") &&
|
||||
s.countUntil("Fletcher") && s.countUntil("Fletcher") != 4 &&
|
||||
s.countUntil("Miller") > s.countUntil("Cooper") &&
|
||||
abs(s.countUntil("Smith") - s.countUntil("Fletcher")) != 1 &&
|
||||
abs(s.countUntil("Cooper") - s.countUntil("Fletcher")) != 1)
|
||||
.writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue