Display a linear combination: Difference between revisions

Line 27:
=={{header|Perl 6}}==
<lang perl6>sub linear-combination(@coeff) {
none(@coeff Z=> map { "e($_)" ??}, '0'1 !!.. *)\
join.grep(+*.key)\
.map({ .key ~ '+*', ~ .value })\
.join('+')\
map { .key ~ '*' ~ .value },
.subst('+-', '-', :g)\
grep +*.key,
.subst(/<|w>1\*/, '', :g);
(@coeff Z=> map { "e($_)" }, 1 .. *)
)\ || '0'
.subst('+-', '-', :g)\
.subst(/<|w>1\*/, '', :g);
}
 
say linear-combination(@$_) for
[1, 2, 3],
[0, 1, 2, 3],
Line 48 ⟶ 46:
[-1, -1, -1],
[-1, -2, 0, -3],
[ -1 ]
;</lang>
{{out}}
1,934

edits