Jump to content

Display a linear combination: Difference between revisions

Added 11l
(Added 11l)
Line 35:
</pre>
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
<lang 11l>F linear(x)
V a = enumerate(x).filter2((i, v) -> v).map((i, v) -> ‘#.e(#.0)’.format(I v == -1 {‘-’} E I v == 1 {‘’} E String(v)‘*’, i + 1))
R (I !a.empty {a} E [String(‘0’)]).join(‘ + ’).replace(‘ + -’, ‘ - ’)
 
L(x) [[1, 2, 3], [0, 1, 2, 3], [1, 0, 3, 4], [1, 2, 0], [0, 0, 0], [0], [1, 1, 1], [-1, -1, -1], [-1, -2, 0, 3], [-1]]
print(linear(x))</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>
 
=={{header|C}}==
1,481

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.