Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Solving a maths problem with Perl

by tobyink (Canon)
on Sep 03, 2020 at 11:30 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11121322]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found