Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,11 +1,9 @@
|
|||
import std.stdio: writeln;
|
||||
|
||||
T[][] permutations(T)(T[] items) {
|
||||
T[][] permutations(T)(T[] items) pure nothrow {
|
||||
T[][] result;
|
||||
|
||||
void perms(T[] s, T[] prefix=[]) {
|
||||
void perms(T[] s, T[] prefix=[]) nothrow {
|
||||
if (s.length)
|
||||
foreach (i, c; s)
|
||||
foreach (immutable i, immutable c; s)
|
||||
perms(s[0 .. i] ~ s[i+1 .. $], prefix ~ c);
|
||||
else
|
||||
result ~= prefix;
|
||||
|
|
@ -15,7 +13,9 @@ T[][] permutations(T)(T[] items) {
|
|||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
foreach (p; permutations([1, 2, 3]))
|
||||
writeln(p);
|
||||
version (permutations1_main) {
|
||||
void main() {
|
||||
import std.stdio;
|
||||
writefln("%(%s\n%)", [1, 2, 3].permutations);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue