-
-
Notifications
You must be signed in to change notification settings - Fork 740
Open
Description
I found a problem with https://dlang.org/phobos/std_algorithm_sorting.html#.nthPermutation :
import std.stdio;
import std.algorithm;
void main()
{
int[] a = [0, 1, 2];
nthPermutation(a, 1); // produces 102 instead of 021
writeln(a);
}
nextPermutation
works well:
int[] a = [0, 1, 2];
do
{
writeln(a);
}
while (nextPermutation(a));
Output:
[0, 1, 2] // nthPermutation(a, 0); OK
[0, 2, 1] // !!! nthPermutation(a, 1); produces 102 instead of 021
[1, 0, 2] // nthPermutation(a, 2); OK
[1, 2, 0] // OK
[2, 0, 1] // OK
[2, 1, 0] // OK
Version: Linux, DMD64 D Compiler v2.111.0
Metadata
Metadata
Assignees
Labels
No labels