Display a linear combination: Difference between revisions

→‎{{header|Perl 6}}: more compact code. Arguably more obscure, but still probably OK
m (→‎{{header|Perl 6}}: forgot to remove a line)
(→‎{{header|Perl 6}}: more compact code. Arguably more obscure, but still probably OK)
Line 27:
=={{header|Perl 6}}==
<lang perl6>sub linear-combination(@coeff) {
my @terms = none(@coeff Z=> map { "e($_)" }, 1?? ..'0' *;!!
join(
 
my $result = join '+',
@terms.=grep(+*.key);
map { .key ~ '*' ~ .value },
 
@terms.= grep( +*.key);,
return '0' unless @terms;
(@coeff Z=> map { "e($_)" }, 1 .. *)
 
)\
my $result = join '+',
map { .key ~ .subst('*+-', ~ .value }'-', :g)\
.subst(/<|w>1\*/, '', :g);
@terms;
 
$result ~~ s:g/'+-'/-/;
$result ~~ s:g/<|w>1\*//;
return $result;
}
 
1,934

edits