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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Given the following contrived problem:

Print out the sum of the numbers from 1 to 100.
The average programmer would probably see this as something to be written with a loop, a nice O(n) problem, and might code it in perl as follows:
#!/usr/bin/perl -w use strict; my $n = 100; my $sum = 0; $sum += $_ for 1 .. $n; print "$sum\n";

Give the same problem to a mathematician, and might be seen as:

Sum(1..n) = n(n+1)/2
however it may ultimately be coded -- a nice O(1) problem.

The programmer will implement the algorithm provided in the most efficient way possible, hopefully, whereas the mathematician is the one who should provide the most efficient algorithm.

If these two work together, we might get a program like this:

#!/usr/bin/perl -w use strict; my $n = 100; my $sum = $n * ( $n + 1 ) / 2; print "$sum\n";
which runs in essentially the same amount of time for any number, n, rather than taking longer and longer to run -- see first program, above.

Many times I've seen people say, "Let the programmer solve it all...he'll make it go fast!" But what about the other disciplines? By involving the mathematician, her algorithms are implemented by the programmer to produce even faster code.

How many of your projects incorporate the disciplines necessary for the realization of the most efficient solution possible?

Pondering,
-v

Update:
Kudos to St. grinder for catchin' a typo: a few missing $ signs in the last example.

"Perl. There is no substitute."

In reply to Problem Domains and Multiple Disciplines by Velaki

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (4)
    As of 2021-02-27 19:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?