in reply to sort of misunderstanding of sort

I assume you want the cross-product of a list with itself.

sort can't do this because it's designed to be fast with O(n*log(n))

There used to be a way to change the applied algorithm, but that's deprecated now https://perldoc.perl.org/sort

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: sort of misunderstanding of sort
by LanX (Saint) on Mar 21, 2023 at 11:51 UTC
    > I assume you want the cross-product

    DB<34> sub cross (&$$) { my ($code,$list1,$list2) = @_; local ($a,$b +); my @res; for $a (@$list1) { for $b (@$list2) { push @res, &$code } +}; return @res; } DB<35> x cross { $a + $b } [0..2], [10,20,30] 0 10 1 20 2 30 3 11 4 21 5 31 6 12 7 22 8 32 DB<36>

    you can just let $list2 default to $list1 if undef to have a self-operation with only one list.

    $list2 //= $list1

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery