[Question]
  [
Given an integer **n** ≥ 1, output a 2D representation† of a percent sign of width **n**. The construction goes as follows:
1. Create an **n** by **n** matrix (or list of lists) filled with zeroes.
2. Insert ones in the top-left and bottom-right corners.
3. Place ones on the diagonal from the bottom-left to the top-right.
For input **n** = 4, this construction would look like:
```
1. 4x4 matrix of 0s
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
2. 1s in TL and BR corners
1 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1
3. 1s across BL-TR diagonal
1 0 0 1
0 0 1 0
0 1 0 0
1 0 0 1
```
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest program in bytes wins.
† I use a matrix of 1s and 0s, but it is also acceptable to use a string of any non-whitespace character and spaces. So, the example above could look like:
```
#  #
  # 
 #  
#  #
```
or
```
#     #
    #
  # 
#     #
```
## Test cases
```
n
output
1
1
2
1 1
1 1
3
1 0 1
0 1 0
1 0 1
4
1 0 0 1
0 0 1 0
0 1 0 0
1 0 0 1
10
1 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 1
```
## Final note
Adding an explanation would be greatly appreciated.
  
[Answer]
## JavaScript (ES6), 52 bytes
```
n=>[...Array(n)].map((_,y,a)=>a.map(_=>y++%~-n<1|0))
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
²Rm’Ṭs
```
[Try it online!](https://tio.run/##AToAxf9qZWxsef//wrJSbeKAmeG5rHP/w4dHIOG4t@KAnCBDYWxsIGxpbmsuIFByZXR0eSBwcmludC7//zEw "Jelly – Try It Online")
### How it works
```
²Rm’Ṭs  Main link. Argument: n
²       Square; yield n².
 R      Range; yield [1, ..., n²].
   ’    Decrement; yield n-1.
  m     Modular; yield every (n-1)-th element of the range, staring with the first.
    Ṭ   Untruth; yield a Boolean array with 1's at the specified indices.
     s  Split the resulting array into chunks of length n, creating a matrix.
```
[Answer]
# [V](https://github.com/DJMcMayhem/V), 15 bytes
```
Àé ÀÄ|r#L.|ò.kl
```
[Try it online!](https://tio.run/##K/v//3DD4ZUKQKKlpkjZR6/m8Ca97Jz///@bAAA "V – Try It Online")
### Explanation
```
Àé<space>        " Argument times insert a space
ÀÄ               " Argument times duplicate this line
                 " This gives an arg-by-arg matrix of spaces
                 "  and brings the cursor to the end of the first line
|r#              " Go to the beginning of this line and replace the first character with #
L.               " Go to the end of this matrix (bottom-right corner) and replace that character with a #
|                " Go to the beginning of the last line
ò                " Recursively do:
 .               "  Repeat the last action, r#, replace the character under the cursor with #
 kl              "  Go 1 up and 1 right
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~58~~ 57 bytes
```
n=input()
x='#'.ljust(n-1)*3
exec'print x[:n];x=x[1:];'*n
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P882M6@gtERDk6vCVl1ZXS8nq7S4RCNP11BTy5grtSI1Wb2gKDOvRKEi2iov1rrCtiLa0CrWWl0r7/9/QwMA "Python 2 – Try It Online")
[Answer]
# GNU APL, ~~17~~ 15 bytes
```
{1=⍵∨⍵⍵⍴1=⍳⍵-1}
```
This is one weird day ... GNU actually beat Dyalog APL ... woah.
TIO doesn't support GNU APL ...
Explanation (input is `⍵`):
```
1=⍳⍵-1 - 1 followed by ⍵-2 0's
⍵⍵⍴    - fit into a square
⍵∨     - gcd ⍵ (0 gcd n = n)
1=     - test each element for equality with 1
```
[Answer]
# [Python 2](https://docs.python.org/2/), 46 bytes
```
lambda n:zip(*[iter(`10L**n`[:-3]*-~n+'1')]*n)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPqiqzQEMrOrMktUgjwdDAR0srLyHaStc4Vku3Lk9b3VBdM1YrT/N/Wn6RQp5CZp5CUWJeeqqGoY6pgaYVF2dBUWZeiUKeTk5qnkaaRp6m5n8A "Python 2 – Try It Online")
Outputs like 
```
[('1', '0', '0', '1'), ('0', '0', '1', '0'), ('0', '1', '0', '0'), ('1', '0', '0', '1')]
```
---
# [Python 2](https://docs.python.org/2/), 48 bytes
```
lambda n:zip(*[iter([1]+(n*[0]+[1])[2:]*-~n)]*n)
```
[Try it online!](https://tio.run/##DcqxDkAwFAXQma9442uRYDA08SXVoUJpwtU0XRj8etnOcMKd9gt9duOUD3vOiyWoxweW2qc1su5MxZC6NdVPoXtlZPNCGAmR3RUJ5EHRYlu5qwehyiJEj0SO//AB "Python 2 – Try It Online")
Outputs like 
```
[(1, 0, 0, 1), (0, 0, 1, 0), (0, 1, 0, 0), (1, 0, 0, 1)]
```
---
# [Python 3](https://docs.python.org/3/), 48 bytes
```
lambda n:('%d'*n+'\n')*n%(1,*(*[0]*n,1)[2:]*-~n)
```
[Try it online!](https://tio.run/##Dcq9DkAwFAbQmafoIr33IvETSxNPgqFCkfCRxmLx6uXM53ru9UQdXNuH3R7jZBUM6WTSglT30CxIqMyEpCsGQVZyV5lB8hcc3OkV1AblLZb5X03BJo4uv@EmR2AOHw "Python 3 – Try It Online")
A quite different string-substitution approach in Python 3. Outputs like:
```
1001
0010
0100
1001
```
[Answer]
# Dyalog APL, ~~12~~ ~~11~~ 10 bytes
```
,⍨⍴×,2↓⊢↑×
```
[Try it online](http://tryapl.org/?a=%28%2C%u2368%u2374%D7%2C2%u2193%u22A2%u2191%D7%295&run)
-1 byte thanks to lstefano.
## How?
```
,⍨⍴×,2↓⊢↑×
       ⊢↑× - argument-length extension of the sign of the argument (1)
     2↓    - Drop the first two elements
   ×,      - Prepend a one
,⍨⍴        - Shape into a square array with dimensions of input x input
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
=þ¹UF1Q¦s
```
[Try it online!](https://tio.run/##ATsAxP9qZWxsef//PcO@wrlVRjFRwqZz/8OHRyDhuLfigJwgQ2FsbCBsaW5rLiBQcmV0dHkgcHJpbnQu//8xMA "Jelly – Try It Online")
### How it works
```
=þ¹UF1Q¦s  Main link. Argument: n
  ¹        Identity; yield n.
=þ         Equals table; compare each i in [1, ..., n] with each j in [1, ..., n].
           This yields the n×n identity matrix.
   U       Upend; reverse each row.
    F      Flatten the matrix.
       ¦   Sparse application:
      Q        Unique; yield the unique elements of the constructed array, i.e.,
               [1] if n = 1 and [0, 1] if n > 1.
     1         Yield 1.
           This replaces the elements at indices 0 (last) and 1 (first) with 1.
        s  Split the resulting array into chunks of length n.
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 18 bytes
```
{⍵=1:⍵⋄⍵ ⍵⍴1=⍳⍵-1}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///3/FR24TqR71bbQ2tgOSj7hYgqQBi9W4xtH3UuxnI1DWsBao7tALIMwUA "APL (Dyalog Unicode) – Try It Online")
Making this work for input 1 has added 6 bytes.
Looking at testcase 4, we see the output is
```
1 0 0 1
0 0 1 0
0 1 0 0
1 0 0 1
```
This is basically 1 0 0 repeated throughout the matrix. In other words, 1 0 0 shaped in a 4-by-4 matrix. So in this solution, we first generate this vector with 1 and trailing 0s using `1=⍳⍵-1` and then shape it using `⍵ ⍵⍴`. But this borks for input 1, so we need to create a conditional and gain 6 bytes...
```
{⍵=1:⍵⋄⍵ ⍵⍴1=⍳⍵-1}    The right argument is ⍵
 ⍵=1:⍵                 If ⍵ is 1 return itself
⋄                      Otherwise
 ⍳⍵-1                   Create a range 1 .. ⍵-1
 1=                     Equals 1; 1 0 0 {⍵-2 0's} ...
 ⍵ ⍵⍴                   Shape in a ⍵-by-⍵ matrix
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~14~~ ~~11~~ 7 bytes
```
n<ÝI<Öô
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/z@bwXE@bw9MOb/n/3wQA "05AB1E – Try It Online")
**Explanation**
```
n<Ý      # push range [0 ... n^2-1]
   I<Ö   # check each for equality to 0 when modulus with n-1 is taken
      ô  # split in pieces of size n
```
[Answer]
# [Haskell](https://www.haskell.org/), 55 bytes
At first my approach was to recursively generate the transposed identity matrix, but then fixing the first and last line required some ugly/lengthy case distinctions. So I looked for another way to generate the identity matrix which is how I found [this](https://codegolf.stackexchange.com/a/70397/48198) idea.
```
f n=[[sum[1|x+y`elem`[2,n+1,2*n]]|y<-[1..n]]|x<-[1..n]]
```
[Try it online!](https://tio.run/##PYtBC4IwHEfv@xQ/RqemgkKXSD9BnTqukUKKo@3vcEoKfvelBd4e7/Hayr9rY0JoQLmUfrQyXSYxl7WpbSmziEQaZUdSapkvsUyTZMNpx8BspQk5GqMdbOVuT2zppHDAgxAXeHUMcONwH/orrZbTGRxCwLfdB7TG/@Z6TcPam5/bB85Z@AI "Haskell – Try It Online")
### Explanation
```
[[x+y|y<-[1..n]]|x<-[1..n]]
```
generates this *matrix* (for `n=4`):
```
[2,3,4,5]
[3,4,5,6]
[4,5,6,7]
[5,6,7,8]
```
As you can see the top left element is `2` (in general), all the diagonal elements are `5` (in general `n+1`) and the bottom right element is `8` (in general `2*n`). So all we need to do is to check if `x+y` is an element of `[2,n+1,2*n]`.
[Answer]
# [R](https://www.r-project.org/), ~~54~~ 42 bytes
*-12 bytes thanks to Jarko Dubbeldam*
```
n=scan();m=diag(n)[,n:1];m[1,1]=m[n,n]=1;m
```
returns a matrix; reads from stdin. creates an identity matrix `diag(n)`, flips it top to bottom `[,n:1]`, sets the top left and bottom right to `1`, and then writes to console (`''`) with width `n`.
[Try it online!](https://tio.run/##K/r/P8@2ODkxT0PTOtc2JTMxXSNPM1onz8ow1jo32lDHMNY2NzpPJy/W1tA697/pfwA)
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
XyPl5L(
```
Try it at [MATL Online!](https://matl.io/?code=XyPl5L%28&inputs=7&version=20.2.1)
### Explanation
Create identity matrix (`Xy`), flip vertically (`P`), write (`(`) value 1 (`l`) to the first and last entries (`5L`), which are the top left and bottom right.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 67 bytes
```
param($n)0..--$n|%{-join(("1"+"0"*(($n-1),0)[!$n])*3)[$_..($_+$n)]}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/vyCxKDFXQyVP00BPT1dXJa9GtVo3Kz8zT0NDyVBJW8lASUsDKKtrqKljoBmtqJIXq6llrBmtEq@np6ESrw3UF1v7//9/CwA "PowerShell – Try It Online")
Takes input `$n` and loops from `0` to `--$n` (i.e., `$n` pre-decremented). Each iteration, we construct a string of `1` followed by `$n-1` `0`s, then multiply that out `3` times (e.g., `100010001000` for input of `5`). Then we index into that on a rotating basis starting from `0` to `0 + $n`. Those characters are `-join`ed into a string, which is left on the pipeline. Output is implicit.
---
*(NB -- This requires an additional 9 bytes to handle the special case of `n=1`. Below is the 58-byte code if we're guaranteed `n>1`)*
```
param($n)0..--$n|%{-join(("1"+"0"*($n-1))*3)[$_..($_+$n)]}
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform),121 91 88 bytes
-30 bytes because the old way was stupid.
-3 bytes by moving around the variable initialization
```
n=>{int i=0,k=n-1;int[,]b=new int[n,n];b[0,0]=b[k,k]=1;for(;i<n;)b[i++,k--]=1;return b;}
```
[Try it online!](https://tio.run/##VY5Ba4QwEIXP5lfM0WAsbq/Z7KWwsNCWlrb0IB7UTWV0O0ISW0T87TbRdqEDgeG9@V5ebdO6N3oZLFIDL6N1@lMyVl9Ka@GZTQz8WFc6rOGrxzM8lEgxX@XNDHMcqN4jOeFfLooDNKBgIXWYvACoMtEpSndysytF@hvCToIKWeWZyApV5Z3oCrWTH72JJe5J8irHJBFdmgbZaDcYgkrOi2RRyD09Pr29qtvM9/0rsn0wqiZeTe4vQ9xvC5@6yjJJkE8siu56sv1F37wbdPoeSceBuCKtR9or0nJv/UfiMUfRFgGa1w4zm5cf "C# (.NET Core) – Try It Online")
Loops iterates down the array to fill in the 1's. Returns an array of 1's and 0's.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 14 12 7 bytes
-5 bytes thanks to [Neil](https://codegolf.stackexchange.com/users/17602/neil)!
```
↗Ｎ⸿/‖Ｏ↘
```
[Try it online!](https://tio.run/##ASAA3/9jaGFyY29hbP//4oaX77yu4ri/L@KAlu@8r@KGmP//NA "Charcoal – Try It Online")
[Answer]
## C++, 144 bytes
```
#include<string>
#define S std::string
S p(int n){S r;for(int i=0;i<n;++i){r+=S(n,32);r[r.size()-1-i]=35;r+=10;}r[0]=r[r.size()-2]=35;return r;}
```
It takes advantage of the one byte difference between '#' and 35
[Answer]
# Mathematica, 72 bytes
```
(s=Table[0,#,#];s[[1,1]]=s[[#,#]]=1;Table[s[[#+1-i,i]]=1,{i,#}];Grid@s)&
```
**input**
> 
> [5]
> 
> 
> 
**output**
> 
> 1 0 0 0 1  
> 
> 0 0 0 1 0  
> 
> 0 0 1 0 0  
> 
> 0 1 0 0 0  
> 
> 1 0 0 0 1
> 
> 
> 
[Answer]
# [Python 2](https://docs.python.org/2/), ~~86~~ 62 bytes
```
n=input();a=('1'+'0'*(n-2))*2+'1'
exec'print a[:n];a=a[1:];'*n
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P882M6@gtERD0zrRVkPdUF1b3UBdSyNP10hTU8tIGyjAlVqRmqxeUJSZV6KQGG2VFwtUmBhtaBVrra6V9/@/OQA "Python 2 – Try It Online")
-24 bytes: Thanks to an idea from Rod!
[Answer]
# Dyalog APL v16, 23 bytes
```
{(1@(1 1)(⍵ ⍵))⌽∘.=⍨⍳⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1Hf1EdtE6o1DB00DBUMNTUe9W5VAGJNzUc9ex91zNCzfdS74lHvZqBQren//wA)
Explanation:
```
{(1@(1 1)(⍵ ⍵))⌽∘.=⍨⍳⍵} -(input ⍵) 
                ∘.=⍨⍳⍵  - identity matrix with size ⍵×⍵
               ⌽        - flip that
 (1@(1 1)(⍵ ⍵))         - place 1 into the corners using the v16 operator @ (At)
```
[Answer]
## Lua, 117 bytes
```
m=arg[1]+0 for y=m,1,-1 do s=""for x=1,m do s=s..((x==1 and y==m or x==m and y==1 or x==y)and"#"or" ")end print(s)end
```
[Try it](https://tio.run/##LcpLCoAwDATQq4S4abGKAbc5ibgoVEWwVloFPX2sn9UMb2Y5rIhnG6eO@rKBMUS42BsyFYELkBjxsZPJ@A9SXSt1MhPY1eUze3gPOX@gHy6dAQsMEQH1kMctzuuu0tNFpL0B) 
Code is pretty simple. It sets m to the first argument, then adds 0 to it to convert it to a number, then iterates backwards for the Y coord, forward through the X coord and will put a # if x==y or if it's the other corners. 
*This program never uses the keyword "if".* 
[Answer]
# Octave, 37 bytes
```
@(n)sparse([1 n:-1:1 n],[1 1:n n],!0)
```
[Try it online!](https://tio.run/##y08uSSxL/f/fQSNPs7ggsag4VSPaUCHPStfQCkjF6gA5hlZ5IJaigeb/NNvEvGJrrrTSnByNNA1DTU0Y0wjBNEYwTRBMUyDzPwA "Octave – Try It Online")
Generates a sparse matrix representing the percent sign.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 12 bytes
```
²ovUÉ hT1 òU
```
Returns a 2D array / matrix.
[Try it online!](http://ethproductions.github.io/japt/?v=1.4.5&code=sm92VckgaFQxIPJV&input=NAotUQ==) using the `-Q` flag to show array-formatted output.
## Explanation
```
²ovUÉ hT1 òU
```
Implicit: `U` = input integer
```
²o
```
Square `U` (`²`), create the array `[0, U*U)` (`o`), and map each item by...
```
vUÉ
```
`1` if it's divisible (`v`) by `U-1` (`UÉ`), else `0`.
```
hT1
```
Set the item (`h`) at index 0 (`T`) to `1`.
```
òU
```
Split the array into slices (`ò`) of length `U`.
[Answer]
# PHP, 53 bytes
```
for(;$i<$l*$l;)echo($i++%($l-1)?0:1).($i%$l?'':"\n");
```
The length of the side of the matrix is `$l`. This code has a PHP Notice and even a PHP Warning for division by 0 when `$l=0`, but does the job!
[Answer]
# [Python 2](https://docs.python.org/2/), 93 bytes
```
n=input()
a='1'+'0'*(n-2)+'1'
print a
for i in range(1,n-1):print str(10**i).zfill(n)
print a
```
[Try it online!](https://tio.run/##Ncs7CoAwEEXRPqtIl5n4wQg2QhaTws@APEOMhW4@CmJ5Odx45XVHXwq8IJ6ZWAVvnKlMZyyh6bl6S8UkyDqoeU9atECngGUiV6NxPH565ESus1a4vWfZNgL/XymDegA "Python 2 – Try It Online")
[Answer]
# Ruby, 47 bytes
```
->n{([1]+[0]*(n-2)).cycle.each_slice(n).take n}
```
It returns an array of arrays.
The code is pretty straightforward.
* It creates a `n-1` array with `1` as the first element and the rest filled with `0`s (e.g. `[1, 0, 0, 0]`)
* It repeats it
* It takes `n` slices of `n` elements
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWiPaMFY72iBWSyNP10hTUy@5MjknVS81MTkjvjgnMzlVI09TryQxO1Uhr/Z/gUJatEnsfwA "Ruby – Try It Online")
[Answer]
# J, 14 bytes
```
-]\*:$1,0$~-&2 
```
Ungolfed:
```
- ]\ (*: $ (1,0 $~ -&2))
```
[Try it online!](https://tio.run/##y/r/P81WTwGEdWNjtKxUDHUMVOp01YwUuFKTM/IV0hRMIQx1dZiAObqA8f//AA "J – Try It Online")
[Answer]
# Python 3, 97 bytes
```
def f(n):
    m=[[0+(j==n-i-1)for j in range(n)]for i in range(n)]
    m[0][0]=1
    m[-1]=m[0]
    return m
```
# Explanation
`m=[[0+(j==n-i-1)for j in range(n)]for i in range(n)]`
This is a list comprehension, the `0+(j==n-i-1)` is a shorter way to convert `j==n-i-1` to an int (as opposed to `int` function)
and then `m[-1]=m[0]` is shorter than making bottom right 1, as top and bottom rows are identical.
[Answer]
## Forth, 273 ( without comments ) 170 ( golfed-ish )
```
: % 2 base ! cr dup 1- 1 swap lshift 1 or . cr 2 over 2 - dup 0< 0= if
0 ?do 2dup s>d rot <# 0 ?do # loop #> type cr 2*  loop
1 or . else drop drop then cr drop decimal ;
```
## ( 273 version to clarify commented version: )
```
: newbase
 base @ swap base ! ;
: 0u.r
 swap s>d rot <# 0 ?do # loop #> type ;
: frame
 1- 1 swap lshift 1 or ;
: %
 2 newbase swap
 cr dup frame . cr
 2 over 2 -
 dup 0< 0= if
  0 ?do
   2dup swap 0u.r cr
   2* 
  loop
  1 or .
 else
  drop drop
 then
cr
drop base ! ;
```
( Note that, since whitespace is the primary delimiter in Forth, removing every carriage return would make no difference. Indentation, of course, does. )
## ( Commented: )
```
( Uses bit array, max 64 width on AMD64 with gforth. )
( Could shave an extra thirty or so bytes by not restoring )
( the numeric base, )
( and a few more by pulling frame and 0u.r into the definition. )
: newbase ( n -- oldbase )  ( swap base with n )
 base @ swap base ! ;
: 0u.r ( u width -- )  ( unsigned numeric output, no leading zero suppression )
 swap s>d rot <# 0 ?do # loop #> type ;
: frame ( n -- f )  ( frame )
 1- 1 swap lshift 1 or ;
: %  ( n -- )  ( Make the % sign )
 2 newbase swap ( Use binary output. )
 cr dup frame . cr ( Frame the first line. )
 2 over 2 -
 dup 0< 0= if ( Are we already done? )
  0 ?do ( Loop doesn't do the first or last. )
   2dup swap 0u.r cr ( Zero fill, right justify. )
   2* 
  loop
  1 or . ( Put the second frame out. )
 else
  drop drop
 then
cr
drop base ! ;
```
## ( Execution examples: )
```
1 % 
1 
 ok
2 % 
11 
11 
 ok
3 % 
101 
010
101 
 ok
10 % 
1000000001 
0000000010
0000000100
0000001000
0000010000
0000100000
0001000000
0010000000
0100000000
1000000001 
 ok
40 % 
1000000000000000000000000000000000000001 
0000000000000000000000000000000000000010
0000000000000000000000000000000000000100
0000000000000000000000000000000000001000
0000000000000000000000000000000000010000
0000000000000000000000000000000000100000
0000000000000000000000000000000001000000
0000000000000000000000000000000010000000
0000000000000000000000000000000100000000
0000000000000000000000000000001000000000
0000000000000000000000000000010000000000
0000000000000000000000000000100000000000
0000000000000000000000000001000000000000
0000000000000000000000000010000000000000
0000000000000000000000000100000000000000
0000000000000000000000001000000000000000
0000000000000000000000010000000000000000
0000000000000000000000100000000000000000
0000000000000000000001000000000000000000
0000000000000000000010000000000000000000
0000000000000000000100000000000000000000
0000000000000000001000000000000000000000
0000000000000000010000000000000000000000
0000000000000000100000000000000000000000
0000000000000001000000000000000000000000
0000000000000010000000000000000000000000
0000000000000100000000000000000000000000
0000000000001000000000000000000000000000
0000000000010000000000000000000000000000
0000000000100000000000000000000000000000
0000000001000000000000000000000000000000
0000000010000000000000000000000000000000
0000000100000000000000000000000000000000
0000001000000000000000000000000000000000
0000010000000000000000000000000000000000
0000100000000000000000000000000000000000
0001000000000000000000000000000000000000
0010000000000000000000000000000000000000
0100000000000000000000000000000000000000
1000000000000000000000000000000000000001 
 ok
```
( Final note: works to one less than the bit width of the Forth interpreter. I ran the above on gforth, AMD64. An ancient 16-bit Forth would only go to 15 bits wide, and would need a bit of modification. )
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 65 bytes
```
w=>{var l=new int[w*w];for(int i=0;i<w*w;i+=w-1)l[i]=1;return l;}
```
[Try it online!](https://tio.run/##XY89awMxDIbn@FdoCfjyUXKz4yyFTi0UOnQINxhHaQWOfdi@mGLy26@6XDu0CGl4pfeRZNPWhojjkMh/wNtXynhRwpsLpt5YBF@FdSYl6KtI2WSycA10ghdDXjZVkM9Q6JQ/QUO7U@Jp8HbP4obz2B3gFaNFntFj0Yd6NRGc9lhgapdV6dQ5RDlBSO8U7VlStNZl2zbuSJ1uVcQ8RA9O3UYlJn8Ycj8w8Bct7@sbJf6RJnV1r0xcN6KKxWPwKTh8eI@UUc4g3sLeBZ0lLX8e0fNHfAP8cTyTR8nDtznGbw "C# (.NET Core) – Try It Online")
The algorithm is significantly distinct from the other C# answer, so I decided to post it separately rather than as an improvement. Inspired by the top rated Jelly answer actually, I was doing something slightly less compact before. The output is a linear array, so would require some logic to wrap it into a 2D outside the method as-is. An alternate version requires 6 additional bytes to output as a true 2D array:
```
w=>{var l=new int[w,w];for(int i=0;i<w*w;i+=w-1)l[i/w,i%w]=1;return l;}
```
I also have an interesting non-competing version.
```
using System.Linq;w=>new int[w*w].Select((_,i)=>i%(w-1)<1)
```
This ends up with almost the right output, resulting in an `IEnumerable<bool>` with true/false instead of 1/0, and it's a linear rather than 2D structure, and although not needed for that exact line of code, `using System.Collections.Generic` is necessary to do anything useful with the output. Like I said, it's very close to being valid but not quite.
]