[Question]
  [
Take a matrix of positive integers as input, and output the individual sums of the elements on the diagonal lines through the matrix. 
You shall only count the lines that goes diagonally down and to the right. You must start with the diagonal that contains only the bottom-left element, then the length-two diagonal above that (if it exists) and so on through to the diagonal that contains only the top-right element, as illustrated below.
**Example:**
```
Input:
 8   14    5    1
10    5    5    8
 6    6    8   10
15   15    4   11
Output:
15, 21, 20, 32, 29, 13, 1
(Diagonals: {{15},{6,15},{10,6,4},{8,5,8,11},{14,5,10},{5,8},{1}})
Input:
1
Output:
1
Input: 
1 5
Output:
1, 5
Input:
4
1
Output: 
1, 4
Input:
17    4    5
24   16    5
 9   24   10
 1   14   22
 1   21   24
 4    4   17
24   25   17
Output:
24, 29, 22, 39, 47, 70, 43, 9, 5
```
Input and output formats are optional as always.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest submission in each language wins.
  
[Answer]
# [Haskell](https://www.haskell.org/), ~~40~~ 37 bytes
```
z=0:z
foldl1$(.(++z)).zipWith(+).(0:)
```
[Try it online!](https://tio.run/nexus/haskell#lYpNCoAgFAb3neItWih@iA8yIvAcLcRFEJLQH9HKy5sdod0wMyU7M@Ymunhuy8at0EKpLKXO6ZrSswoltTCjLPucDnJ03el4qKVI3g/gDhYc4NlUsBgq9uhRi/lsjRYdmEMoP/8X "Haskell – TIO Nexus") Usage: `(foldl1$(.(++z)).zipWith(+).(0:)) [[1,2,3],[4,5,6]]`.
**Edit:** Thanks to Ørjan Johansen for -3 bytes!
### Ungolfed:
```
z = 0:z
s#t = zipWith(+)(0:s)(t++z)
f m = foldl1 (#) m
```
`z` is a list of infinitely many zeros. In `f` we fold over the list of lists `m` by combining two lists with the function `#`. In `#` the first list `s` contains the accumulated column sums so far and the second list `t` is the new row which should be added. We shift `s` one element to the right by adding a zero to the front and element-wise add `s` and `t` with `zipWith(+)`. Because `s` might be arbitrarily large, we have to pad `t` with enough zeros by appending `z`.
[Answer]
# Mathematica, ~~53~~ 54 bytes
```
l=Length@#-1&;Tr@Diagonal[#,k]~Table~{k,-l@#,l@#&@@#}&
```
Pure function taking a 2D-array as input and returning a list. (Entries don't have to be integers or even numbers.) `Diagonal[#,k]` returns the `k`th diagonal above (or below, if `k` is negative) the main diagonal. `{k,-l@#,l@#&@@#}` computes the range of diagonals needed based on the dimensions of the input array. And `Tr` sums the entries of each diagonal.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 6 bytes
```
T&XdXs
```
[Try it online!](https://tio.run/nexus/matl#@x@iFpESUfz/f7SFgqGJgqmCobWCoQGQNlWwsFYwA0KguAFQzBSETBQMDWMB "MATL – TIO Nexus") Or [verify all test cases](https://tio.run/nexus/matl#HUw5DsAgDNv7Ck@dSUSAirVPYEBCSB36g/5f1EG5HMfxs9rZ3/6tu61RIBEGqZDAaSgViUE@kDPPCJF5jF0w9siLL5knq1AKkoNrQ/9zV1UHyqQ@ukveWqVpnj8).
### Explanation
```
T&Xd   % All diagonals of implicit input arranged as zero-padded columns
Xs     % Sum of each column. Implicitly display
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
0;+µ/
```
[Try it online!](https://tio.run/nexus/jelly#TU7JDYQwDPynivkTidgKx4oCtogozfChGb40AJ3QSNZOAtnHSJ5TTm7pzqNP13av@zelYBACZgvyFhgEFK0BArnKFXPRMMqt0LyrOfEVkD5RFDEv/l268TJfl16fptKVTHZYd8bG8bHImnua5VfmxlnxLPv6y9T2eMg8mvgD "Jelly – TIO Nexus")
### How it works
```
0;+µ/  Main link. Argument: M (matrix / array of rows)
   µ   Combine all links to the left into a chain (arity unknown at parse time) and
       begin a new monadic chain.
    /  Reduce M by that chain. This makes the chain dyadic.
       Let's call the arguments of the chain L and R (both flat arrays).
0;         Prepend a 0 to L.
  +        Perform element-wise addition of the result and R.
           When the chain is called for the n-th time, R has n less elements, so
           the last n elements of L won't have matching elements in R and will be
           left unaltered.
```
[Answer]
## JavaScript (ES6), ~~65~~ 58 bytes
```
a=>a.map(b=>b.map((c,i)=>r[i]=~~r[i]+c,r=[,...r]),r=[])&&r
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~22~~ 21 bytes
Saved 1 byte thanks to Martin Ender
```
{_,({0\f+}*ee::m<:.+}
```
Anonymous block expecting the argument on the stack and leaves the result on the stack.
[Try it online!](https://tio.run/nexus/cjam#K6z7Xx2vo1FtEJOmXauVmmpllWtjpadd@7@u4H90tKG5AhCYgAjTWK5oIxDL0AzGVbAEMiBiBiCuIYgF4hoZwbhGYMIExDWBGWVoDjPKyBTCjQUA "CJam – TIO Nexus")
**How it works**
```
_                   e# Duplicate the matrix
 ,(                 e# Get its length (# of rows) minus 1
   {0\f+}*          e# Prepend that many 0s to each row
          ee        e# Enumerate; map each row to [index, row]
            ::m<    e# Rotate each row left a number of spaces equal to its index
                :.+ e# Sum each column
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 17 bytes
```
Rvy¹gÅ0«NFÁ}})øO¨
```
[Try it online!](https://tio.run/nexus/05ab1e#@x9UVnloZ/rhVoNDq/3cDjfW1moe3uF/aMX//9HRhuY6JjqmsTrRRiY6hmZglqUOiG0AZBnqGJroGBmBWUZAZAJkmQDVG5pDNBiZgpixAA "05AB1E – TIO Nexus")
**Explanation**
```
R                  # reverse input
 v                 # for each N,y (index, item)
  y¹gÅ0«           # pad y with as many zeroes as the number of rows in the input
        NFÁ}       # rotate each row N times right
            })     # wrap the result in a list
              øO   # sum the columns
                ¨  # remove the last element of the resulting list (the padded zeroes)
```
[Answer]
# [J](http://jsoftware.com/), 7 bytes
```
+//.@|.
```
[Try it online!](https://tio.run/nexus/j#U9JTT1OwtVJQV9BRMFCwAmJdPQXnIB0ft//a@vp6DjV6/zW5UpMz8hXSFEwUTFSU9NQV1LPyM/OKS4oy89JtrPXiDWutNHzcoNo1uRQsFBQUDE2AhIIpiDDkMjSAc8CEBZeCGYgGE2DVBlyGIBkwoQDSamjIpfkfAA "J – TIO Nexus")
This is pretty simple:
```
+//.@|.
+/        sum
  /.      on oblique lines
    @|.   on the reversed array
```
Oblique reversed lines are the diagonals of the array, so this is just summing the diagonals.
[Answer]
# [Python 2](https://docs.python.org/2/), 62 bytes
```
lambda M:reduce(lambda x,y:map(sum,zip([0]+x,y+[0]*len(x))),M)
```
[Try it online!](https://tio.run/nexus/python2#bU/LCoMwELznK/aY1ByS4KtCP8EvSHOwVUFQEVvB9uftrkak4GFIZrIzs6nhBvelLbpHWUCejVU5PSvu@Sw/WVcM/DV18tsM3CoXoBbgeWmrns9CCJmLZRib/g01Z2AtpBJ0KAEihHaSAVitPCekmwYx3gk0r/wcvhMA/Vo7xwRjf9mnGuWe6KHvOfHoZOtA3zpjqC8@OFwlrJraM7Y/GXNwQ9g7Qr9zcuSZaOXYvfwA "Python 2 – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ŒDS€ṙZL$
```
**[Try it online!](https://tio.run/nexus/jelly#@390kkvwo6Y1D3fOjPJR@f//f3S0obmOgomOgmmsDpdCtJGJjqEZjKNgqQPiG0A4hjqGJjpGRjCOERCZQDgmIAMMzWEGGJmCOLEA "Jelly – TIO Nexus")**
Half of the code is used to put the results into the correct order.
### How?
```
ŒDS€ṙZL$ - Main link: list of lists of numbers
ŒD       - diagonals (starts with the diagonal containing the top left element,
         -            then the next diagonal to the right, and so on wrapping around)
  S€     - sum €each
       $ - last two links as a monad
     Z   - transpose the matrix
      L  - length (width of the matrix)
    ṙ    - rotate the results left by that amount
```
[Answer]
# Perl 5, 47 bytes
```
map{$j=--$.;map{@a[$j++]+=$_}split}<>
print"@a"
```
[Answer]
## R, 45 bytes
Unnamed function taking a matrix-class object as input:
```
function(x)sapply(split(x,col(x)-row(x)),sum)
```
Using the idea explained in [this](https://codegolf.stackexchange.com/a/100958/56989) answer.
[Answer]
# Octave, 71 bytes
Assuming A is a matrix, for example:
```
A = [17 4 5;24 16 5; 9 24 10; 1 14 22; 1 21 24; 4 4 17;24 25 17];
```
Then we have:
```
[m,n]=size(A);
a=[zeros(m,m-1),A]';
for i=1:m+n-1
trace(a(i:end,:))
end
```
Notice that transposing the matrix reverses the ordering of the diagonal sums, which saved an overall two bytes in the for loop.
Output:
```
ans =  24
ans =  29
ans =  22
ans =  39
ans =  47
ans =  70
ans =  43
ans =  9
ans =  5
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 7 bytes
```
ÞD?L‹ǔṠ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLDnkQ/TOKAuceU4bmgIiwiIiwiW1sxNywgNCwgNV0sIFsyNCwgMTYsIDVdLCBbOSwgMjQsIDEwXSwgWzEsIDE0LCAyMl0sIFsxLCAyMSwgMjRdLCBbNCwgNCwgMTddLCBbMjQsIDI1LCAxN11dIl0=)
Takes 4 bytes to get it in the right order. If the order didn't matter, it would be 3 bytes (remove the `?L‹ǔ`).
[Answer]
# Python, 126 bytes
```
x=input()
f=lambda k:[x[i+k][i]for i in range(len(x)-k)]
a=map(f,range(4)[::-1])
x=zip(*x)
print(map(sum,a+map(f,range(1,4))))
```
`f` only works on the lower triangular section, so I transpose it and get the upper triangular section that way. Don't know why the `f` function doesn't work for negative values (I changed `f` to be shorter because the part to get the negatives didn't work).
[Answer]
# C, 148 bytes
[**Try Online**](http://ideone.com/oRcerv)
```
s;g(int i,int j,int**m,int x){for(s=0;x;x--)s+=m[i++][j++];printf(" %d",s);}
k;f(int n,int**m){for(k=n;--k;)g(k,0,m,n-k);for(;k<n;k++)g(0,k,m,n-k);}
```
[Answer]
# PHP, 81 Bytes
Take Input as 2 D Array
```
<?foreach($_GET as$k=>$v)foreach($v as$x=>$y)$r[$x-$k]+=$y;ksort($r);print_r($r);
```
[Try it online!](https://tio.run/nexus/php#s7EvyCjgUol3dw2xjY620DE00THVMYzl0ok2NACyTHUsQGwzHTMdoJwBWBwob6pjomNoGBtr/T8tvyg1MTlDA2yCQmKxSratnUqZJly4DCRWARSr1FQpilap0FXJjtW2Vam0zi7OLyrRUCnStC4oyswriS8Cs///BwA "PHP – TIO Nexus")
[Answer]
# Awk, 67 Bytes
```
{for(f=0;f++<NF;)s[NF-NR+f]+=$f}END{i=0;while(i++<NR*2)print s[i]}
```
Ungolfed:
```
{
    for (f = 0; f++ < NF;)
        s[NF-NR+f] += $f
}
END {
    i = 0
    while (i++ < NR*2)
        print s[i]
}
```
Awk splits on whitespace `$n` is the `n`th field (1-indexed); `NF` is the number of fields on the line, `NR` is the number of the current row. Undefined variables are 0 and created on first use.
[Answer]
# PHP, 86 bytes
a memory friendly solution in two variants:
```
<?for($i=$c=count($a=$_GET);--$i>-$c;print$s._)for($s=0,$d=$c;$d--;)$s+=$a[$i+$d][$d];
<?for($i=$c=count($a=$_GET);--$i>-$c;print$s._)for($s=$d=0;$d<$c;)$s+=$a[$i+$d][$d++];
```
takes input from script parameters, uses underscore as delimiter;  
use default settings (not default php.ini) or [try them online](http://sandbox.onlinephpfunctions.com/code/8d0eacededdc003bc00054e0805c2dae98177eb8)
[Answer]
## Clojure, 81 bytes
```
#(apply map +(map(fn[i c](concat(repeat(-(count %)i 1)0)c(repeat i 0)))(range)%))
```
Quite verbose, as it pads lists with zeros so that we can just calculate the column-wise sum.
[Answer]
## mathematica 73 bytes
```
Plus@@@Table[Diagonal[Partition[#1,#2[[1]]],k],{k,-#2[[2]]+1,#2[[1]]-1}]&
```
This one works for ANY 2D-array m x n (not only nxn)  
input the array at the end of the code like this (the last test case)
```
[{17,4,5,24,16,5,9,24,10,1,14,22,1,21,24,4,4,17,24,25,17},{3,7}]
```
> 
> {24, 29, 22, 39, 47, 70, 43, 9, 5}
> 
> 
> 
input in form [{a,b,c,d...},{m,n}]
[Answer]
# [Husk](https://github.com/barbuz/Husk/wiki/Commands), 6 [bytes](https://github.com/barbuz/Husk/wiki/Codepage)
```
mΣ∂m↔T
```
[Try it online.](https://tio.run/##yygtzv7/P/fc4kcdTbmP2qaE/P//PzraQsfQRMdUxzBWJ9rQAMgw1bEAMs10zHSAMgYgUaCkqY6JjqFhbCwA)
**Explanation:**
```
     T  # Transpose the (implicit) argument; swapping rows/columns
   m↔   # Reverse each row
  ∂     # Take the anti-diagonals of this matrix
mΣ      # And sum each inner anti-diagonal list
        # (after which the result is output implicitly)
```
]