Display a linear combination: Difference between revisions
Content deleted Content added
Alextretyak (talk | contribs) Added 11l |
|||
Line 35: | Line 35: | ||
</pre> |
</pre> |
||
<br><br> |
<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}}== |
=={{header|C}}== |