Display a linear combination: Difference between revisions
Content added Content deleted
No edit summary |
(Add tests lists to task description) |
||
Line 12: | Line 12: | ||
* you don't show scalars when they are equal to one or minus one. For instance the string "1*e(3)" is wrong. |
* you don't show scalars when they are equal to one or minus one. For instance the string "1*e(3)" is wrong. |
||
* you don't prefix by '-' if it follows a preceding term. Instead you use subtraction. Thus "e(4) - e(5)" is correct while "e(4) + -e(5)" is wrong. |
* you don't prefix by '-' if it follows a preceding term. Instead you use subtraction. Thus "e(4) - e(5)" is correct while "e(4) + -e(5)" is wrong. |
||
Show here output for the following lists of scalars: |
|||
<pre>1) 1.1, 2.2, 3.4 |
|||
2) 0, 1.1, 2, 3 |
|||
3) 1.1, 0, 3.3, 4.4 |
|||
4) 1.1, 2.2, 0.0 |
|||
5) 0.0, 0, 0.0 |
|||
6) 0 |
|||
7) 1, 1, 1.0 |
|||
8) -1.0, -1, -1 |
|||
9) -1.1, -2.2, -3.3 |
|||
10) -1</pre> |
Revision as of 15:07, 11 October 2015
Display a linear combination is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
The purpose of this task is to display a finite linear combination in an infinite vector basis .
Write a function that, when given a finite list of scalars , creates a string representing the linear combination
Your output must comply to the following rules:
- you don't show null terms, unless the whole combination is null. For instance while the output "0" is fine, "e(0) + 0*e(3)" or "0 + e(1)" are wrong.
- you don't show scalars when they are equal to one or minus one. For instance the string "1*e(3)" is wrong.
- you don't prefix by '-' if it follows a preceding term. Instead you use subtraction. Thus "e(4) - e(5)" is correct while "e(4) + -e(5)" is wrong.
Show here output for the following lists of scalars:
1) 1.1, 2.2, 3.4 2) 0, 1.1, 2, 3 3) 1.1, 0, 3.3, 4.4 4) 1.1, 2.2, 0.0 5) 0.0, 0, 0.0 6) 0 7) 1, 1, 1.0 8) -1.0, -1, -1 9) -1.1, -2.2, -3.3 10) -1