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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Update: THIS IS A WRONG IMPLEMENTATION. PLease don't++ it!! Thanks, buk.

I'm getting different results from other people, so this is probably wrong, but then maybe not, so...

#! perl -slw use strict; use List::Util qw[ reduce ]; $a = $a; ## Disable the dumbest warning in perl! my @samples = ( ## r1 r2 r3 [ qw[ 0.11 0.07 0.19 ] ], [ qw[ 0.43 0.31 0.37 ] ], [ qw[ 0.93 0.78 0.82 ] ], [ qw[ 0.91 0.12 0.15 ] ], [ qw[ 0.52 0.18 0.32 ] ], ); sub P{ return 1 if @_ == 1; my @r = @_; return reduce { $a + ( $r[ $b ] - $r[ $b - 1 ] ) * P( @r[ 0 .. ( $#r - $b ) ] + ) } 0 .. $#r; } my @results = map P( @$_ ), @samples; print "@results"; __END__ P:\test>380259 0.1216 0.0744 0.0624999999999999 0.6541 0.2556

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re: recursive formula. by BrowserUk
in thread recursive formula. by BioGeek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-03-28 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found