Matrix with two diagonals: Difference between revisions

Content added Content deleted
Line 2,539: Line 2,539:
</pre>
</pre>


=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'matrix'

class Matrix
def self.two_diagonals(n)
Matrix.build(n, n) do |row, col|
row == col || row == n-col-1 ? 1 : 0
end
end
end

Matrix.two_diagonals(5).row_vectors.each{|row| puts row.to_a.join(" ") }</syntaxhighlight>
{{out}}
<pre>
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
</pre>
=={{header|Sidef}}==
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func dual_diagonal(n) {
<syntaxhighlight lang="ruby">func dual_diagonal(n) {