March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -1,22 +1,21 @@
import std.stdio, std.algorithm, std.range, std.array, std.conv;
// http://rosettacode.org/wiki/Combinations#D
import combinations4: Comb;
alias int[] iRNG;
alias iRNG = int[];
iRNG setDiff(iRNG s, iRNG c) {
return setDifference(s, c).array();
return setDifference(s, c).array;
}
iRNG[][] orderPart(iRNG blockSize...) {
iRNG sum = iota(1, 1 + blockSize.reduce!q{a + b}()).array();
iRNG sum = iota(1, 1 + blockSize.sum).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 .. $]))
foreach (r; p(setDiff(s, c), b.dropOne))
res ~= c.dup ~ r;
return res;
}
@ -24,11 +23,7 @@ iRNG[][] orderPart(iRNG blockSize...) {
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);
void main(in string[] args) {
auto b = args.length > 1 ? args.dropOne.to!(int[]) : [2, 0, 2];
writefln("%(%s\n%)", b.orderPart);
}