Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,15 +1,13 @@
import std.stdio;
T[][] comb(T)(in T[] arr, in int k) pure nothrow {
if (k == 0) return [[]];
typeof(return) result;
foreach (i, x; arr)
foreach (immutable i, immutable x; arr)
foreach (suffix; arr[i + 1 .. $].comb(k - 1))
result ~= x ~ suffix;
return result;
}
void main() {
//import std.stdio: writeln;
[0, 1, 2, 3].comb(2).writeln();
import std.stdio;
[0, 1, 2, 3].comb(2).writeln;
}

View file

@ -1,13 +1,12 @@
import std.stdio, std.algorithm, std.range;
T[][] comb(T)(in T[] s, in int m) /*pure nothrow*/ {
T[][] comb(T)(in T[] s, in int m) /*pure*/ nothrow {
if (!m) return [[]];
if (s.empty) return [];
return s[1 .. $].comb(m - 1).map!(x => s[0] ~ x)().array() ~
return s[1 .. $].comb(m - 1).map!(x => s[0] ~ x).array ~
s[1 .. $].comb(m);
}
void main() {
//import std.stdio: writeln;
iota(4).array().comb(2).writeln();
4.iota.array.comb(2).writeln;
}

View file

@ -0,0 +1,25 @@
#define system.
#define system'routines.
#define extensions.
#define extensions'routines.
#symbol M = 3.
#symbol N = 5.
// --- Numbers ---
#symbol numbers = (:anN)
[
arrayControl new &length:anN &each: anIndex [ Integer new:(anIndex + 1) ]
].
// --- Program ---
#symbol program =
[
#var aNumbers := numbers:N.
controlEx for:(Combinator new:(arrayControl new &length:M &each: i [ aNumbers ])) &do: aRow
[
consoleEx writeLine:aRow.
].
].

View file

@ -1,3 +1,3 @@
for i in @task combinations(1:5,3)
println(i)
for i in combinations(1:5,3)
print(i')
end