Alternating Pattern
Python 2, 62 bytes
lambda n:["%*s"%(i%2*2*n-n,"x"*min(i+1,n-i))for i in range(n)]
Try it online!
Uses x
and space.
The rows are computed like this:
"%-5s" % "x" == "x "
"%5s" % "xx" == " xx"
"%-5s" % "xxx" == "xxx "
"%5s" % "xx" == " xx"
"%-5s" % "x" == "x "
Using the %*s
specifier to choose between n
and -n
.
Jelly, 9 bytes
>þµoṚUÐeY
Try it online!
Explanation
>þ Create a table of (x>y) over [1…n]×[1…n]:
[0 1 1 1 1]
[0 0 1 1 1]
[0 0 0 1 1]
[0 0 0 0 1]
[0 0 0 0 0]
µ Take this array, and...
oṚ OR it with its reverse:
[0 1 1 1 1]
[0 0 1 1 1]
[0 0 0 1 1]
[0 0 1 1 1]
[0 1 1 1 1]
UÐe Apply U (reverse) to even-indexed rows.
Y Join by newlines.
APL (Dyalog Classic), 18 bytes
⎕a[↑⊢∘⌽\(⊂>⊢⌊⌽)⍳⎕]
Try it online!
outputs AB
instead of *#
⎕
evaluated input n
⍳⎕
the vector 0 1 ... n-1
⊢⌊⌽
min (⌊
) between themselves (⊢
) and their reverse (⌽
) - see trains
⊂>⊢⌊⌽
where is the ⍳
vector as a whole (⊂
) less than each of its ⊢⌊⌽
- return a vector of boolean (0/1) vectors
⊢∘⌽\
reverse every other vector
↑
mix into a matrix
⎕a
the uppercase English alphabet, 'AB
...Z'
⎕a[
]
replace 0
1
with 'A'
'B'