tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,34 @@
import std.stdio, std.algorithm, std.range, std.array, std.conv;
// http://rosettacode.org/wiki/Combinations#D
import combinations4: Comb;
alias int[] iRNG;
iRNG setDiff(iRNG s, iRNG c) {
return setDifference(s, c).array();
}
iRNG[][] orderPart(iRNG blockSize...) {
iRNG sum = iota(1, 1 + blockSize.reduce!q{a + b}()).array();
iRNG[][] p(iRNG s, in iRNG b) {
if (b.length == 0)
return [[]];
iRNG[][] res;
foreach (c; Comb.On(s, b[0]))
foreach (r; p(setDiff(s, c), b[1 .. $]))
res ~= c.dup ~ r;
return res;
}
return p(sum, blockSize);
}
void main(string[] args) {
auto b = args.length > 1 ?
args[1 .. $].map!(to!int)().array() :
[2, 0, 2];
foreach (p; orderPart(b))
writeln(p);
}