23
2
Given (by any means):
- A two-argument (or single argument consisting of a two-element list) black box function,
f: ℤ+ × ℤ+ → ℤ+(input and output are 1, 2, 3,…) - A strictly positive integer matrix with at least two rows and two columns
return the matrix's function trace.
What is a function trace?
A normal matrix trace is the sum of the major diagonal (top-left to bottom-right) of a matrix:
[[1,2,3],[4,5,6],[7,8,9]] → [1,5,9] → 1+5+9 → 15
But instead of summing, we want to apply f along the diagonal:
[[1,2,3],[4,5,6],[7,8,9]] → [1,5,9] → f(f(1,5),9) or f(1,f(5,9))
Please state whether you use left-to-right or right-to-left.
The given matrix and all intermediate values will be strictly positive integers within your language's integer domain. The matrix may be non-square.
Examples
f(x,y) = xy, [[1,2,3],[4,5,6],[7,8,9]] → 1×5×9 → 45
f(x,y) = xy, [[1,2,3],[4,5,6],[7,8,9]] → 159 → 1
f(x,y) = x-y, [[4,5,6],[1,2,3]] → 4-2 → 2
f(x,y) = (x+y)⁄2, [[2,3,4],[5,6,7],[8,9,10]] → 5 or 7
f(x,y) = x+2y, [[1,2,3],[4,5,6],[7,8,9]] → 47 or 29
f(x,y) = max(x,y), [[1,2,3],[4,5,6],[7,8,9]] → max(1,5,9) → 9
f(x,y) = 2x, [[1,2,3],[4,5,6],[7,8,9]] → 2 or 4
f(x,y) = lcm(x,y), [[2,2,2],[2,2,3],[2,3,3],[4,4,4]] → lcm(2,2,3) → 6
What is the diagonal of
[[2,2,2],[2,2,3],[2,3,3],[4,4,4]]? – totallyhuman – 2018-01-24T12:21:18.3103@totallyhuman:
[2,2,3]– Emigna – 2018-01-24T12:22:27.8171Dammit, I read the title as "Generalized Matrix trance" and was sorely disappointed when the page loaded – tar – 2018-01-25T14:50:10.733