tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
21
Task/Permutations/D/permutations-1.d
Normal file
21
Task/Permutations/D/permutations-1.d
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import std.stdio: writeln;
|
||||
|
||||
T[][] permutations(T)(T[] items) {
|
||||
T[][] result;
|
||||
|
||||
void perms(T[] s, T[] prefix=[]) {
|
||||
if (s.length)
|
||||
foreach (i, c; s)
|
||||
perms(s[0 .. i] ~ s[i+1 .. $], prefix ~ c);
|
||||
else
|
||||
result ~= prefix;
|
||||
}
|
||||
|
||||
perms(items);
|
||||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
foreach (p; permutations([1, 2, 3]))
|
||||
writeln(p);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue