"be consistent" PerlMonks

### Re: Re: Re: Re: (Golf) Multiply polynomials

by Masem (Monsignor)
 on May 08, 2001 at 18:14 UTC ( #78822=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: (Golf) Multiply polynomials

D'oh, I see where I was going wrong, I was reading it as [3,2] being 3x+2. Now I see ability to whack zeros with no problem :D

However, to nitpick, the 75 char solution (update above), isn't strict; you need to add 12 characters to strict-ify it. (my@m, for my \$i, for my \$p, my\$j ), so to compare with the other solutions, at least mine being all strict, you're at 87.

Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re (tilly) 5: (Golf) Multiply polynomials
by tilly (Archbishop) on May 08, 2001 at 18:29 UTC
Nitpicking some more, if you want strict I can give you 84 characters:
```sub p{
my@m=1;for my\$p(@_){my@a;for my\$i(0..@m){my\$j;\$a[\$i+\$j++]+=\$_*\$m[\$i]fo
+r@\$p}@m=@a}\@m
}
And note that I handle 0 or more polynomials correctly. (The empty product in math is "1".)
This must be under 5.6 or the like; "for my\$p" and "for my\$i" lead to interpreter problems under 5.005_02 (Win32). Bug or feature change?
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Um, bug. I was too glib.

But that makes getting a strict version with a count of 84 a point of honour, right? :-)

```sub p{
my@m=1;for my \$p(@_){my@a;map{my\$j=my\$i=\$_;\$a[\$j++]+=\$_*\$m[\$i]for@\$p}0
+..@m;@m=@a}\@m
}

Create A New User
Node Status?
node history
Node Type: note [id://78822]
help
Chatterbox?
 [jdporter]: Dang. No good example of how to use IPC::Run's run() in its simplest mode? [LanX]: him or her! ;) [1nickt]: jdporter Maybe try IPC::Run3 [LanX]: Sandy Koufax is indeed rude. .. oO [chacham]: Re: Re: pattern matching -- feeling stoopit a poll idea about centrists, is +8 -5, used to be +6/-6 how apropos :)is +8 [chacham]: [chacham]: ooh, late, nighty nite everybody

How do I use this? | Other CB clients
Other Users?