Matrix with two diagonals: Difference between revisions

Content added Content deleted
(Added AutoHotkey)
Line 362: Line 362:
0 1 0 0 0 0 0 1 0
0 1 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 1</pre>
1 0 0 0 0 0 0 0 1</pre>

=={{header|AutoHotkey}}==
<lang AutoHotkey>for i, v in [8, 9]
result .= "Matrix Size: " v "*" v "`n" matrix2txt(diagonalMatrix(v)) "`n"
MsgBox % result
return

diagonalMatrix(size){
M := []
loop % size {
row := A_Index
loop % size
M[row, A_Index] := (row = A_Index || row = size-A_Index+1) ? 1 : 0
}
return M
}

matrix2txt(M){
for row , obj in M {
for col, v in obj
result .= M[row, col] " "
result .= "`n"
}
return result
}</lang>
{{out}}
<pre>Matrix Size: 8*8
1 0 0 0 0 0 0 1
0 1 0 0 0 0 1 0
0 0 1 0 0 1 0 0
0 0 0 1 1 0 0 0
0 0 0 1 1 0 0 0
0 0 1 0 0 1 0 0
0 1 0 0 0 0 1 0
1 0 0 0 0 0 0 1

Matrix Size: 9*9
1 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
0 0 1 0 0 0 1 0 0
0 1 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 1 </pre>


=={{header|AWK}}==
=={{header|AWK}}==