Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: finding highest number

by Anonymous Monk
on Dec 05, 2002 at 13:09 UTC ( [id://217750]=note: print w/replies, xml ) Need Help??


in reply to Re: finding highest number
in thread finding highest number

thanks LTjake this is cool, but how could you adapt it to calculate second and third highest numbers also??

Replies are listed 'Best First'.
Re: Re: Re: finding highest number
by petral (Curate) on Dec 05, 2002 at 17:11 UTC
        how could you adapt it to calculate second and third highest numbers?

    something like:
    use strict; my @array = (1, 5, 4, 10, 20, 2, 1, 3, 7); my @hi = (0) x 3; # '0' assumes positive #'s foreach (@array) { $_ <= $hi[0] and next; @hi = (sort $a<=>$b, @hi, $_)[-3..-1]; } print "@hi";
    (untested)   (and, as said, of course the sort method would be better, at least for small arrays, and would be even more better for finding the top three values:  (sort ..., @array)[-3..-1] )

      p

Log In?
Username:
Password:

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

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

    No recent polls found