Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to find the N largest values in an array?

by merlyn (Sage)
on Oct 04, 2001 at 00:16 UTC ( [id://116557]=note: print w/replies, xml ) Need Help??


in reply to How to find the N largest values in an array?

If you mean "the three consecutive values that when summed make up the highest total", then that gives an implementation strategy:
my $where = 0; my $sum = $num[0] + $num[1] + $num[2]; for ( 1 .. $#sum-2 ) { my $try = $num[$_] + $num[$_+1] + $num[$_+2]; if ( $try > $sum ) { $try = $sum; $where = $_; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found