Display a linear combination: Difference between revisions

Content added Content deleted
(Tcl implementation added)
(→‎{{header|Perl 6}}: add spaces in output)
Line 28:
.grep(+*.key)\
.map({ .key ~ '*' ~ .value })\
.join(' + ')\
.subst('+ -', '- ', :g)\
.subst(/<|w>1\*/, '', :g)
|| '0'
}
 
say linear-combination($_) for
[1, 2, 3],
Line 47:
;</lang>
{{out}}
<pre>e(1) + 2*e(2) + 3*e(3)
e(2) + 2*e(3) + 3*e(4)
e(1) + 3*e(3) + 4*e(4)
e(1) + 2*e(2)
0
0
e(1) + e(2) + e(3)
-e(1) - e(2) - e(3)
-e(1) - 2*e(2) - 3*e(4)
-e(1)</pre>