9. Grand Total
In this problem, you’re asked to enter your own APL function, without giving it any arguments. Your function will be checked by the APL Challenge system using several tests to see whether it is correct.
You can use round brackets ( (…) ) to change the order in which things are
calculated. In problem 4 you learnt that an APL
function takes the result of all code to its right as its right
argument. This was a simplification; the right argument only goes as far
as the nearest closing bracket of any type (…
or ]…
or )…
) on its right:}
2×3+4gives14because×takes the result of all code to its right,3+4, as its right argument.2×(3+4)gives14because×takes the result of all code to its right,(3+4), as its right argument.(2×3)+4gives10because the right argument of×only goes as far as the nearest closing bracket.
Write a function that takes a matrix and uses + with /, (…), and , and gives a list of numbers. The list must be the sum of each row followed by the sum of all the numbers in the matrix. (This means that the result list has one more number than the number of rows in the matrix.) For example:
{answer} [1 2
3 4]
3 7 10
{answer} [1 3
2 4
7 8]
4 6 15 25
{answer} [1 0 1 0
1 1 1 1
1 1 0 1]
2 4 3 9