Permutations: Difference between revisions

Content added Content deleted
m (→‎Lazy version: missing imports)
(Added demo code second D version)
Line 852: Line 852:
[3, 2, 1]</pre>
[3, 2, 1]</pre>
===Lazy version===
===Lazy version===
With same main function produces the same output:
Compiled with <code>-version=permutations2_main</code> produces the same output:
<lang d>import std.exception, std.bigint;
<lang d>import std.algorithm, std.exception;


struct Permutations(T) {
struct Permutations(T) {
Line 913: Line 913:
foreach (p; permutations([BigInt(1), BigInt(2), BigInt(3)]))
foreach (p; permutations([BigInt(1), BigInt(2), BigInt(3)]))
assert((p[0] + 1) > 0);
assert((p[0] + 1) > 0);
}

version (permutations2_main) {
void main() {
import std.stdio;
foreach (p; permutations([1, 2, 3]))
writeln(p);
}
}</lang>
}</lang>