in reply to Re: Combinatorial problem
in thread Combinatorial problem
You are creating a lot of duplicates. May I offer some humble adjustments:
use strict; use warnings; 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 @result; my @diagonal = map { $MTX->[$_][$_] } 0..5; for my $i (0..5) { for my $j ($i+1..5) { for my $k ($j+1..5) { my $sc = 0; $sc += $diagonal[$_] for ($i, $j, $k); next unless $sc > 17; push @result, [$i, $j, $k, $sc]; } } } print "@$_\n" for @result;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Combinatorial problem
by Laurent_R (Canon) on Apr 24, 2015 at 06:44 UTC |