Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Solving a maths problem with Perl

by tobyink (Canon)
on Sep 03, 2020 at 11:30 UTC ( #11121322=note: print w/replies, xml ) Need Help??


in reply to Solving a maths problem with Perl

And yes, I'm aware it can be solved without object-oriented programming.

use v5.16; package Local::App2 { use List::Util 'sum'; use Exporter::Shiny 'S'; sub a { my $n = shift; 1 + (1/$n); } sub S { my $n = shift; sum( map a($_), 1 .. $n ); } } use Local::App2 'S'; say S(15);

I like using OOP though because of the ease with which parts can be overridden, like in the rational number version.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2021-06-19 17:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (93 votes). Check out past polls.

    Notices?