Hm, not sure to understand everything that you are doing, but this is my proposed solution:
use strict; use warnings; use Data::Dumper; my $MTX = [ [4,-1,-2,-2, 0,-1], [-1,5, 0, 2,-3, 1], [-2,0, 6, 1,-3, 5], [-2,2, 1, 7,-3, 0], [0,-3,-3,-3, 8,-3], [-1,1, 5, 0,-3, 9], ]; my (@diagonal, @result); my $k = 3; for my $i (0..5) { push @diagonal, $MTX->[$i][$i]; } for my $i (0..5) { for my $j (0..5) { for my $k (0..5) { next if $i == $j or $i == $k or $j == $k; my $sc; $sc += $diagonal[$_] for ($i, $j, $k); next unless defined $sc; next if $sc < 17; push @{$result[$sc]}, [$i, $j, $k]; } } } print Dumper \@result;
The result is as follows:
$VAR18 = [ [ 0, 1, 4 ], [ 0, 2, 3 ], [ 0, 3, 2 ], [ 0, 4, 1 ], [ 1, 0, 4 ], [ 1, 4, 0 ], [ 2, 0, 3 ], [ 2, 3, 0 ], [ 3, 0, 2 ], [ 3, 2, 0 ], [ 4, 0, 1 ], [ 4, 1, 0 ] ]; $VAR19 = [ [ 0, 1, 5 ], [ 0, 2, 4 ], [ 0, 4, 2 ], [ 0, 5, 1 ], [ 1, 0, 5 ], [ 1, 2, 3 ], [ 1, 3, 2 ], [ 1, 5, 0 ], [ 2, 0, 4 ], [ 2, 1, 3 ], [ 2, 3, 1 ], [ 2, 4, 0 ], [ 3, 1, 2 ], [ 3, 2, 1 ], [ 4, 0, 2 ], [ 4, 2, 0 ], [ 5, 0, 1 ], [ 5, 1, 0 ] ]; $VAR20 = [ [ 0, 2, 5 ], [ 0, 3, 4 ], [ 0, 4, 3 ], [ 0, 5, 2 ], [ 1, 2, 4 ], [ 1, 4, 2 ], [ 2, 0, 5 ], [ 2, 1, 4 ], [ 2, 4, 1 ], [ 2, 5, 0 ], [ 3, 0, 4 ], [ 3, 4, 0 ], [ 4, 0, 3 ], [ 4, 1, 2 ], [ 4, 2, 1 ], [ 4, 3, 0 ], [ 5, 0, 2 ], [ 5, 2, 0 ] ]; $VAR21 = [ [ 0, 3, 5 ], [ 0, 5, 3 ], [ 1, 2, 5 ], [ 1, 3, 4 ], [ 1, 4, 3 ], [ 1, 5, 2 ], [ 2, 1, 5 ], [ 2, 5, 1 ], [ 3, 0, 5 ], [ 3, 1, 4 ], [ 3, 4, 1 ], [ 3, 5, 0 ], [ 4, 1, 3 ], [ 4, 3, 1 ], [ 5, 0, 3 ], [ 5, 1, 2 ], [ 5, 2, 1 ], [ 5, 3, 0 ] ]; $VAR22 = [ [ 0, 4, 5 ], [ 0, 5, 4 ], [ 1, 3, 5 ], [ 1, 5, 3 ], [ 2, 3, 4 ], [ 2, 4, 3 ], [ 3, 1, 5 ], [ 3, 2, 4 ], [ 3, 4, 2 ], [ 3, 5, 1 ], [ 4, 0, 5 ], [ 4, 2, 3 ], [ 4, 3, 2 ], [ 4, 5, 0 ], [ 5, 0, 4 ], [ 5, 1, 3 ], [ 5, 3, 1 ], [ 5, 4, 0 ] ]; $VAR23 = [ [ 1, 4, 5 ], [ 1, 5, 4 ], [ 2, 3, 5 ], [ 2, 5, 3 ], [ 3, 2, 5 ], [ 3, 5, 2 ], [ 4, 1, 5 ], [ 4, 5, 1 ], [ 5, 1, 4 ], [ 5, 2, 3 ], [ 5, 3, 2 ], [ 5, 4, 1 ] ]; $VAR24 = [ [ 2, 4, 5 ], [ 2, 5, 4 ], [ 4, 2, 5 ], [ 4, 5, 2 ], [ 5, 2, 4 ], [ 5, 4, 2 ] ]; $VAR25 = [ [ 3, 4, 5 ], [ 3, 5, 4 ], [ 4, 3, 5 ], [ 4, 5, 3 ], [ 5, 3, 4 ], [ 5, 4, 3 ] ];
I leave it up to you to check the results.

Je suis Charlie.

In reply to Re: Combinatorial problem by Laurent_R
in thread Combinatorial problem by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.