Permutations: Difference between revisions
Content added Content deleted
(Added missing in lazy D version) |
|||
Line 851: | Line 851: | ||
[3, 1, 2] |
[3, 1, 2] |
||
[3, 2, 1]</pre> |
[3, 2, 1]</pre> |
||
===Lazy version=== |
===Faster Lazy version=== |
||
Compiled with <code>-version=permutations2_main</code> produces the same output: |
Compiled with <code>-version=permutations2_main</code> produces the same output: |
||
<lang d>import std.algorithm, std.exception; |
<lang d>import std.algorithm, std.exception; |
||
Line 886: | Line 886: | ||
} |
} |
||
void popFront() { |
void popFront() /*pure nothrow*/ { |
||
tot--; |
tot--; |
||
if (tot > 0) { |
if (tot > 0) { |
||
Line 911: | Line 911: | ||
return Permutations!T(items); |
return Permutations!T(items); |
||
} unittest { |
} unittest { |
||
import std.bigint; |
|||
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); |