import std.stdio; import std.array; import std.range; import std.algorithm;
void main() { auto arr = [64, 64, 64, 32, 31, 16, 32, 33, 64]; auto newarr = arr[]; bool state = true; while (arr.length) { newarr = state ? array(until!("a < 32")(arr)) : array(until!("a >= 32")(arr)); arr = arr[newarr.length .. $]; state ^= 1; writeln(newarr); } } The idea is to find as many elements in a sequence that conform to some predicate, followed by as many elements that conform to another predicate. The two predicates are switched on each run. The above code will print: [64, 64, 64, 32] [31, 16] [32, 33, 64] Is there a better way to do this, some std.range/algorithm function I don't know of?