[Issue 9878] New: std.algorithm.cartesianProduct results order

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 4 19:48:55 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9878

           Summary: std.algorithm.cartesianProduct results order
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-04-04 19:48:53 PDT ---
This is an example of Python usage of its product() function:

>>> from itertools import product
>>> list(product([0, 1], repeat=3))
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0),
(1, 1, 1)]



This is a similar usage of Phobos std.algorithm.cartesianProduct:


import std.stdio, std.algorithm, std.string, std.conv, std.array;
void main() {
    auto bits = [0, 1];
    auto p = cartesianProduct(bits, bits, bits);
    p.text.replace("Tuple!(int, int, int)", "").writeln;
}


Its output:

[(0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 0, 1), (1, 0, 1), (0, 1, 1),
(1, 1, 1)]

I'd like cartesianProduct() to give its results in the same order as Python. If
you see in Python the results are like the binary numbers:

000
001
010
011
100
101
110
111

I think this is a more natural and more useful order.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list