Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Finding the max()/min()

by pg (Canon)
on Nov 11, 2004 at 03:25 UTC ( #406898=note: print w/replies, xml ) Need Help??


in reply to Finding the max()/min()

A recursive solution for a list of numbers: (the idea to get max for a list is originally gotten from elusion's post)

use strict; use warnings; print max(1.23,2.6,55.1,1.11,4,5); print min(1.23,2.6,55.1,1.11,4,5); sub max { splice(@_, ($_[0] > $_[1]) ? 1 : 0, 1); return ($#_ == 0) ? $_[0] : max(@_); } sub min { splice(@_, ($_[0] > $_[1]) ? 0 : 1, 1); return ($#_ == 0) ? $_[0] : min(@_); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://406898]
help
Chatterbox?
[marto]: good morning all, sane dots all round
[Corion]: Hi marto! I hope all is well!
[marto]: Corion, pretty much. How are things? You were at LPW?

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2016-12-07 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (125 votes). Check out past polls.