Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I know it's a tad late, but here is my $0.01. To my opinion PDL is neglected around here, and I know I use it too little myself.

With the help of PDL I only use 43 chars for the sub, and if I looked right, it's a record in this thread. You may add 8 chars if you want to account for the extra 'use PDL;' statement:

use PDL: sub p{$t=pdl+pop;$t=$t*(pdl$_)for@_;[list$t]}
This doesn't work with arrays of unequal length, but that wasn't in the spec. The output:
print join " ", @{p([1..5],[1..5])}; 1 4 9 16 25
BTW, tilly, why did you name it 'polynomials'? Isn't it just a breed of recursive vector multiplication? Do I miss something?

And, 'strictness' requires only 3 extra chars with a total of 46/54 chars (54 still is the record):

sub p{my $t=pdl+pop;$t=$t*(pdl$_)for@_;[list$t]}
"We are not alone"(FZ) Update Thx to tye I now know why tilly talked about polynomials. Sorry. If we still want a matrix-kind solution, it would be like:
A = p1'*p2; product = crossdiags(A);
But that's difficult to code in PDL, unfortunately. Here is my 2nd attempt, works only if poly's are equal length (pathetic 164 chars):
sub p{$t=pdl+pop;for(@_){ my $a=outer$t,pdl+pop; transpose($a); my $n=-1+nelem$t; $t=zeroes($n*2+1); $t->slice("$_:".($_+$n))+=$a->slice("$_,:")for 0..$n; } [list$t]}
Will ponder it a bit more and get back....

In reply to Re: (Golf) Multiply polynomials by jeroenes
in thread (Golf) Multiply polynomials by tilly

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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (9)
    As of 2018-06-19 13:20 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (114 votes). Check out past polls.