Display a linear combination: Difference between revisions
Content added Content deleted
(Added Kotlin) |
(Added Julia language) |
||
Line 162: | Line 162: | ||
fourbanger _1 |
fourbanger _1 |
||
-e(1)</lang> |
-e(1)</lang> |
||
=={{header|Julia}}== |
|||
<lang julia># v0.6 |
|||
linearcombination(coef::Array) = join(collect("$c * e($i)" for (i, c) in enumerate(coef) if c != 0), " + ") |
|||
for c in [[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]] |
|||
@printf("%20s -> %s\n", c, linearcombination(c)) |
|||
end</lang> |
|||
{{out}} |
|||
<pre> [1, 2, 3] -> 1 * e(1) + 2 * e(2) + 3 * e(3) |
|||
[0, 1, 2, 3] -> 1 * e(2) + 2 * e(3) + 3 * e(4) |
|||
[1, 0, 3, 4] -> 1 * e(1) + 3 * e(3) + 4 * e(4) |
|||
[1, 2, 0] -> 1 * e(1) + 2 * e(2) |
|||
[0, 0, 0] -> |
|||
[0] -> |
|||
[1, 1, 1] -> 1 * e(1) + 1 * e(2) + 1 * e(3) |
|||
[-1, -1, -1] -> -1 * e(1) + -1 * e(2) + -1 * e(3) |
|||
[-1, -2, 0, -3] -> -1 * e(1) + -2 * e(2) + -3 * e(4) |
|||
[-1] -> -1 * e(1)</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |