Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Combinatorial problem

by hdb (Monsignor)
on Apr 24, 2015 at 06:13 UTC ( [id://1124491]=note: print w/replies, xml ) Need Help??


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
    You are creating a lot of duplicates.
    Yes, I know, but I had the feeling the OP wanted to keep the duplicates. Well, I still don't know what the OP really wanted, I just tried to offer something simpler.

    Je suis Charlie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1124491]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-18 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found