Generate the diamond of alphabets as per the numbers given in column A. Examples given for 3, 5 & 8.
📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 528
Challenge Difficulty: ⭐️⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn
Solving the challenge of Draw Alphabetic Diamond with Power Query
Power Query solution 1 for Draw Alphabetic Diamond, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
Source = 8,
Letras = List.Transform({65 .. 65 + Source - 1}, each Character.FromNumber(_)),
Rows = List.Transform(
{0 .. Source - 1},
each List.Repeat({null}, _)
& List.Reverse(List.Skip(Letras, _))
& List.Skip(Letras, _ + 1)
& List.Repeat({null}, _)
),
Sol = Table.FromRows(List.Reverse(Rows) & List.Skip(Rows))
in
Sol
Power Query solution 2 for Draw Alphabetic Diamond, proposed by Ramiro Ayala Chávez:
let
Number = 5,
a = List.Reverse(List.FirstN({"A" .. "Z"}, Number)),
b = List.Reverse(
List.Generate(
() => [i = 0, j = 1],
each [j] <= Number,
each [i = [i], j = [j] + 1],
each List.Range(a, 0, [j] - [i]) & List.Reverse(List.Range(a, [i], [j] - 1))
)
),
c = List.Generate(
() => [i = 0],
each [i] < Number,
each [i = [i] + 1],
each List.Repeat({null}, [i]) & b{[i]} & List.Repeat({null}, [i])
),
Sol = Table.FromRows(List.Reverse(List.RemoveFirstN(c)) & c)
in
Sol
Solving the challenge of Draw Alphabetic Diamond with Excel
Excel solution 1 for Draw Alphabetic Diamond, proposed by Bo Rydobon 🇹🇭:
=LET(n,A3,r,ABS(SEQUENCE(n*2-1,,1-n)),s,r+TOROW(r),REPT(CHAR(s+65),s
Excel solution 2 for Draw Alphabetic Diamond, proposed by John V.:
=LET(v,2*A3-1,s,SEQUENCE,i,ABS(s(v)-A3)+ABS(s(,v)-A3),REPT(CHAR(65+i),i
Excel solution 3 for Draw Alphabetic Diamond, proposed by محمد حلمي:
=LET(n,A3,e,SEQUENCE(n*2-1),r,ABS(n-e)+
ABS(n-TOROW(e)),REPT(CHAR(65+r),n>r))
Excel solution 4 for Draw Alphabetic Diamond, proposed by Julian Poeltl:
=LET(N,A3,A,N*2-1,B,ABS(SEQUENCE(A)-N),X,B+TOROW(B),IF(X
Excel solution 5 for Draw Alphabetic Diamond, proposed by Timothée BLIOT:
=LET(A,A3,B,LAMBDA(x,y,ABS(x-A)+ABS(y-A)),C,2*A-1,MAKEARRAY(C,C,LAMBDA(x,y,IF(A>B(x,y),CHAR(B(x,y)+65),""))))
Excel solution 6 for Draw Alphabetic Diamond, proposed by Oscar Mendez Roca Farell:
=LET(
n,
A3,
s,
SEQUENCE(
2*n-1
),
m,
ABS(
n-s
)+ABS(
n-TOROW(
s
)
),
REPT(
CHAR(
m+65
),
m
Excel solution 7 for Draw Alphabetic Diamond, proposed by Sunny Baggu:
=LET(
_r,
A19 * 2 - 1,
_s,
SEQUENCE(
_r
),
_m,
MEDIAN(
_s
),
_ns,
ABS(
_s - _m
) + 1,
_a,
SEQUENCE(
,
_m - 1,
_m - 1,
-1
) + _ns,
_b,
SEQUENCE(
,
_m - 1,
,
1
) + _ns,
_f,
HSTACK(
_a,
_ns,
_b
),
IF(
_f > _m,
"",
CHAR(
_f + 64
)
)
)
Excel solution 8 for Draw Alphabetic Diamond, proposed by Andy Heybruch:
=LET(_n,A19,_size,_n*2-1,MAKEARRAY(_size,_size,LAMBDA(_r,_c,LET(_a,ABS(_n-_r)+ABS(_n-_c),IF(_a<=_n-1,CHAR(_a+65),"")))))
Excel solution 9 for Draw Alphabetic Diamond, proposed by Bilal Mahmoud kh.:
=LET(
a,
5,
s,
VSTACK(
SEQUENCE(
a
),
SEQUENCE(
a-1,
,
a-1,
-1
)
),
lf,
MAP(
s,
LAMBDA(
n,
TEXTJOIN(
",",
,
IFERROR(
HSTACK(
CHAR(
SEQUENCE(
,
a-n,
32,
0
)
),
CHAR(
SEQUENCE(
,
n,
65+a-1,
-1
)
)
),
CHAR(
SEQUENCE(
,
n,
65+a-1,
-1
)
)
)
)
)
),
rt,
MAP(
lf,
LAMBDA(
m,
CONCAT(
MID(
m,
SEQUENCE(
LEN(
m
)-1,
,
LEN(
m
),
-1
)-1,
1
)
)
)
),
TEXTSPLIT(
TEXTJOIN(
"-",
,
lf&rt
),
",",
"-"
)
)
Excel solution 10 for Draw Alphabetic Diamond, proposed by Eddy Wijaya:
=LET(
n,a3,
arr,MAKEARRAY(n*2-1,n*2-1,LAMBDA(r,c,IFS(
OR(r=n,c=n),ABS(r-c)+1,
OR(AND(r-c<=n-1,c<=n,r>=n),
AND(r-c>=-n+1,c>n,r=n+1,c<=n,r<=n),
AND(r+c<=n*3-1,c>n,r>n)),IF(c>n,r-(n*2-c)+1,ABS(r-(n*2-c)-1)),
TRUE,""))),
IFERROR(MAP(arr,LAMBDA(m,CHAR(64+m))),""))
Excel solution 11 for Draw Alphabetic Diamond, proposed by Mey Tithveasna:
=LET(
a,
A3,
r,
SEQUENCE(
a*2-1
),
x,
ABS(
r-a
)+ABS(
TOROW(
r
)-a
),
REPT(
CHAR(
65+x
),
x
Excel solution 12 for Draw Alphabetic Diamond, proposed by Edwin Tisnado:
=LET(n,2*A9-1,m,n/2,s,ABS(SEQUENCE(n,,-m)+0.5),r,s+TOROW(s),IF(r
Excel solution 13 for Draw Alphabetic Diamond, proposed by Tyler Cameron:
=LET(a,ABS(SEQUENCE(A3*2-1,,1-A3)),b,a+TOROW(a),IF(b
Solving the challenge of Draw Alphabetic Diamond with Python
Python solution 1 for Draw Alphabetic Diamond, proposed by Konrad Gryczan, PhD:
import pandas as pd
import numpy as np
def draw_diamond(size):
M = np.full((2 * size - 1, 2 * size - 1), np.nan)
for i in range(2 * size - 1):
for j in range(2 * size - 1):
M[i, j] = abs(abs(i - (size-1)) + abs(j - (size-1))) + 1
M = pd.DataFrame(M).applymap(lambda x: chr(int(x) + 64) if x <= size else "")
return M
Solving the challenge of Draw Alphabetic Diamond with R
R solution 1 for Draw Alphabetic Diamond, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
path = "Excel/528 Diamonds of Alphabets.xlsx"
draw_diamond = function(size) {
M = matrix(NA, nrow = 2 * size - 1, ncol = 2 * size - 1)
for (i in 1:(2 * size - 1)) {
for (j in 1:(2 * size - 1)) {
M[i, j] = abs(abs(i - size) + abs(j - size)) + 1
}
}
M = M %>% as.data.frame() %>% mutate_all(~ifelse(. <= size, LETTERS[.], ""))
return(M)
}
draw_diamond(3)
draw_diamond(5)
draw_diamond(8)
&&&
