> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/m/matrix_with_two_diagonals.md).

# Matrix with two diagonals

```ruby
func dual_diagonal(n) {
    n.of {|k|
        var r = (k.of(0) + [1] + (n - k - 1).of(0))
        r ~Z| r.reverse
    }
}
 
dual_diagonal(5).each{.join(' ').say}; say ''
dual_diagonal(6).each{.join(' ').say}
```

#### Output:

```
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

1 0 0 0 0 1
0 1 0 0 1 0
0 0 1 1 0 0
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 0 0 1
```
