-3
Write a full program to calculate the inverse of a 4-by-4 matrix.
Rules
The sixteen values of the initial matrix must be hard-coded to variables, as follows:
_ _
|a b c d|
|e f g h|
|i j k l|
|m n o p|
- -
Then print the values of the inverse matrix, row by row, with each number separated by some delimiter. You may assume that the given matrix has an inverse.
The results must be completely accurate, limited only by the programming language. For example, you may assume that (1 / 3) * 3 = 1, there's no such thing as integer overflow, and so on.
You may use only the following operations:
- Addition - 10 points
- Subtraction - 15 points
- Multiplication - 25 points
- Division - 50 points
- Assignment to a variable - 2 points
- Printing a variable (not an expression) and a delimiter - 0 points
- Recalling a variable or numeric constant - 0 points
For example: x = (a + b) / (a - 2)
would score 77 points.
To clarify, you may not use any other operations or structures, such as arrays, functions (outside the main method, if needed), if-statements, etc.
The initial hard-coding of the variables does not give any points.
Fewest points wins.
Testcases
Note that all testcases can be used in reverse.
a=1; b=1; c=2; d=-1; e=-2; f=0; g=-2; h=1; i=-1; j=2; k=1; l=0; m=2; n=-1; o=0; p=2
Print, in order: 9 7 -4 1 10 8 -4 1 -11 -9 5 -1 -4 -3 2 0
a=1; b=2; c=3; d=0; e=2; f=2; g=1; h=0; i=4; j=4; k=4; l=4; m=2; n=1; o=-2; p=0
Print, in order: -5 7 0 -4 6 -8 0 5 -2 3 0 -2 1 -2 .25 1
a=-.25; b=.5; c=0; d=.5; e=1; f=.25; g=-.5; h=0; i=-1; j=-.5; k=.5; l=.25; m=.25; n=1; o=0; p=0
Print, in order: -2 4 4 2 .5 -1 -1 .5 -3.75 5.5 7.5 4.25 .5 3 3 .5
Just checking, but creating arrays is not allowed, correct? – James Pringle – 2015-02-04T22:57:08.627
Can we also assume the variables to be stored in an array? I assume we may also use other structures like loops/conditionals etc, do we? – flawr – 2015-02-04T23:16:54.470
Is the score for an operation counted each time the operation is written in the code, or each time it is performed during execution? – feersum – 2015-02-04T23:31:39.937
Can our code fail on a measure zero subset of matrices that cause a divide by zero even though they are invertible? Gaussian elimination is likely to run into this. If not, can we use an if statement? – xnor – 2015-02-05T00:28:32.133
@JamesPringle No. – Ypnypn – 2015-02-05T00:46:48.913
@feersum Performed, though it shouldn't make a difference. – Ypnypn – 2015-02-05T00:49:10.530
@xnor No.. No.. – Ypnypn – 2015-02-05T00:50:27.967
3It makes a huge difference. – feersum – 2015-02-05T00:57:22.723