Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: "Junkyard" Puzzle: Average of Numbers

by no_slogan (Deacon)
on May 13, 2001 at 05:49 UTC ( #79983=note: print w/replies, xml ) Need Help??


in reply to "Junkyard" Puzzle: Average of Numbers

eval(join "+", @{$_[0]}) / @{$_[0]}

Update: Oh, are we golfing? That's 31 characters without the spaces.

Replies are listed 'Best First'.
Re: Re: "Junkyard" Puzzle: Average of Numbers
by mr.nick (Chaplain) on May 13, 2001 at 08:15 UTC
    Damn! I did this one without reading a single other post and came out with a sloppier version that yours, but along the same lines (I'm new at this :)
    sub find_avg { (eval join"+",@{$_[0]})/(($#{$_[0]})+1); }
    I had a hell of a time getting $#array working with $_[0]. I see I over complicated it :)
    I'd like to add that these "Junkyard" puzzles, Golf and such are extremely good practice for those of us lower on the curve. Just in the past week or so, I've added quite a bit of knowledge to my base. These remind me much of doing geometric proofs back in middle school. Entertaining as well as educational.

    Thank you.

Re: Re: "Junkyard" Puzzle: Average of Numbers
by Masem (Monsignor) on May 13, 2001 at 06:04 UTC
    I wouldn't suggest golfing with these. Sure, you could, but that's not the challenge; it's probably more interesting to see how many TIMTOWTDI approaches can be taken.
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://79983]
help
Chatterbox?
[perldigious]: A question since I'm ignorant of what's normal for database management... Do admins change column names a lot in databases?
[perldigious]: On occasion my scripts break, because they will do something that seems laregly pointless to me... like in this case, changing a column name from "ABC Category" to "ABC Category Override".
[perldigious]: Being the ignorant one, my initial reaction to that is, "that's sort of a dick move, a lot of people like me expect column names like that to stay the same, why the hell would you change them like that for seemingly no good reason?"
[perldigious]: Or is my irritation/ frustration well founded?
[Corion]: perldigious: That seems to be more the export and likely it's the recipients of that export that like the titles changes
[Corion]: ... "changed"
[Corion]: I usually expect fixed header names, but am sometimes lenient in the order of columns. But changing the report titles often sounds to me as if you are not the sole consument of the export ;)

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2017-05-25 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?