Home » Build Alphabet Staircase Shape

Build Alphabet Staircase Shape

Create alphabets staircase as shown.

📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 627
Challenge Difficulty: ⭐️⭐️⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn

Solving the challenge of Build Alphabet Staircase Shape with Power Query

Power Query solution 1 for Build Alphabet Staircase Shape, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
  Source = {"A" .. "Z"}, 
  Letras = List.Transform(Source, each List.Repeat({_}, 3)), 
  Comb = List.Combine(
    List.Transform(
      {0 .. List.Count(Source) - 1}, 
      each {List.Repeat({null}, _ * 2) & Letras{_}, List.Repeat({null}, (_ + 1) * 2) & {Source{_}}}
    )
  ), 
  Sol = Table.Transpose(Table.FromColumns(Comb))
in
  Sol
Power Query solution 2 for Build Alphabet Staircase Shape, proposed by Alexandre Garcia:
let
  H = {"A" .. "Z"}, 
  P = 3, 
  L = List.Repeat, 
  C = Table.Combine(
    List.Generate(
      () => 0, 
      each _ < List.Count(H), 
      each _ + 1, 
      each Table.FromRows(
        {L({null}, _ * (P - 1)) & L({H{_}}, P)} & L({L({null}, (_ + 1) * (P - 1)) & {H{_}}}, P - 2)
      )
    )
  )
in
  C
Power Query solution 3 for Build Alphabet Staircase Shape, proposed by Mihai Radu O:
let
  a = {0 .. 25}, 
  b = List.Transform(
    a, 
    (x) =>
      Text.Split(
        Text.Repeat(",", x * 2)
          & Text.TrimEnd(Text.Repeat(Character.FromNumber(x + 65) & ",", 3), ",")
          & Text.Repeat(",", List.Max(a) * 2 - x * 2), 
        ","
      )
  ), 
  c = List.Transform(
    a, 
    (x) =>
      Text.Split(
        Text.Repeat(",", 2 * (x + 1))
          & Character.FromNumber(x + 65)
          & Text.Repeat(",", List.Max(a) * 2 - x * 2), 
        ","
      )
  ), 
  d = Table.FromRows(List.Combine(List.Zip({b, c})))
in
  d

Solving the challenge of Build Alphabet Staircase Shape with Excel

Excel solution 1 for Build Alphabet Staircase Shape, proposed by Bo Rydobon 🇹🇭:
=MAKEARRAY(52,53,LAMBDA(r,c,REPT(CHAR(64+(r+1)/2),ABS(r-c+1)
Excel solution 2 for Build Alphabet Staircase Shape, proposed by John V.:
=MAKEARRAY(52,53,LAMBDA(r,c,REPT(CHAR(64.5+r/2),(ABS(c-r-1)<2)*MOD(r,2)+(c-r=1)*(MOD(r,2)=0))))
or
✅
 =LET(s,SEQUENCE,i,s(52),REPT(CHAR(64.5+i/2),ABS(s(,53)-i-1)-ISODD(i)<1))
Excel solution 3 for Build Alphabet Staircase Shape, proposed by Kris Jaganah:
=MAKEARRAY(52,
    53,
    LAMBDA(x,
    y,
    LET(a,
    y-x,
    b,
    ISODD(
        --x
    ),
    c,
    CHAR(
        x/2+64.5
    ),
    IFS((a=0)*b,
    c,
    (a=2)*b,
    c,
    a=1,
    c,
    1,
    ""))))
Excel solution 4 for Build Alphabet Staircase Shape, proposed by Julian Poeltl:
=MAKEARRAY(52,
    53,
    LAMBDA(A,
    B,
    IF((ISODD(
        B
    )*B=A)+(A+1=B)+(ISODD(
        B
    )*(A+2=B)),
    CHAR(
        64.5+A/2
    ),
    "")))
Excel solution 5 for Build Alphabet Staircase Shape, proposed by Timothée BLIOT:
=MAKEARRAY(52,
    53,
    LAMBDA(x,
    y,
    LET(A,
    CHAR(
        CEILING(
            x/2,
            1
        )+64
    ),
    IF(ISODD(
        x
    )*(x+3>y)*(x
Excel solution 6 for Build Alphabet Staircase Shape, proposed by Sunny Baggu:
=LET(
 n,
     26 * 2,
    
 r,
     SEQUENCE(
         n
     ),
    
 c,
     SEQUENCE(
         ,
          n + 1
     ),
    
 _a,
     MOD(
         c,
          2
     ),
    
 _b,
     _a * 0,
    
 _d,
     ROUNDUP(
         r / 2,
          0
     ),
    
 IF(
 (ABS(
     r - c + 1
 ) = _a) + (ABS(
     r - c + 1
 ) = _b),
    
 CHAR(
     _d + 64
 ),
    
 ""
 )
)
Excel solution 7 for Build Alphabet Staircase Shape, proposed by Abdallah Ally:
=LET(a,
    SEQUENCE(
        26
    ),
    b,
    EXPAND,
    c,
    HSTACK,
    d,
    IFERROR,
    IFNA(DROP( REDUCE("",
    a,
    LAMBDA(x,
    y,
    LET(e,
    CHAR(
        y+64
    ),
    f,
    c(
        e,
        e,
        e
    ),
    g,
    d(c(b("",
    ,
    2*(y-1),
    ""),
    f),
    f),
    h,
    c(
        b(
            "",
            ,
            2*y,
            ""
        ),
        e
    ),
    VSTACK(
        x,
        g,
        h
    )))),
    1),
    ""))
Excel solution 8 for Build Alphabet Staircase Shape, proposed by Jaroslaw Kujawa:
=IFNA(
    DROP(
        REDUCE(
            "";
            CHAR(
                SEQUENCE(
                    ;
                    CODE(
                        "K"
                    )-CODE(
                        "A"
                    )+1;
                    CODE(
                        "A"
                    )
                )
            );
            LAMBDA(
                a;
                x;
                LET(
                    num;
                    3;
                    fakt;
                    CODE(
                        x
                    )-CODE(
                        "A"
                    );
                    wi;
                    REPT(
                        ""&";";
                        2*fakt
                    )&REPT(
                        x&";";
                        num
                    );
                    VSTACK(
                        a;
                        TEXTSPLIT(
                            LEFT(
                                wi;
                                LEN(
                                    wi
                                )-1
                            )&"|"&REPT(
                                ""&";";
                                2*fakt
                            )&REPT(
                                ""&";";
                                num-1
                            )&x;
                            ";";
                            "|"
                        )
                    )
                )
            )
        );
        1
    );
    ""
)

Solving the challenge of Build Alphabet Staircase Shape with Python

Python solution 1 for Build Alphabet Staircase Shape, proposed by Konrad Gryczan, PhD:
import pandas as pd
import numpy as np
import string
path = "627 Alphabets Staircase_2.xlsx"
test = pd.read_excel(path, header=None, usecols="A:BA", nrows=52, skiprows=1)
al = list(string.ascii_uppercase)
M = np.full((52, 53), np.nan, dtype=object)
for i in range(1, 27):
 indices = [(2*i - 2, 2*i - 2), (2*i - 2, 2*i - 1), (2*i - 2, 2*i), (2*i - 1, 2*i)]
 for index in indices:
 M[index[0], index[1]] = al[i-1]
M = pd.DataFrame(M)
test.columns = M.columns
print(test.equals(M))
                    
                  
Python solution 2 for Build Alphabet Staircase Shape, proposed by Abdallah Ally:
import pandas as pd
from string import ascii_uppercase
# Perform data manipulation
values = []
size = 2 * len(ascii_uppercase) + 1
for k, v in enumerate(ascii_uppercase):
 a = [''] * (2 * k) + [v] * 3
 b = [''] * (2 *(k + 1)) + [v]
 c = [''] * (size - len(a))
 values.extend([a + c, b + c])
df = pd.DataFrame(data=values)
df
                    
                  

Solving the challenge of Build Alphabet Staircase Shape with Python in Excel

Python in Excel solution 1 for Build Alphabet Staircase Shape, proposed by Aditya Kumar Darak 🇮🇳:
num = 26
rows = np.arange(2 * num).reshape(-1, 1)
cols = np.arange(2 * num + 1).reshape(1, -1)
r = rows // 2
c = cols - 1
o = rows % 2 == 0
result = np.where(
 (r == c // 2) & o | (r == cols // 2) & o | (rows == c) & ~o,
 np.vectorize(lambda x: chr(65 + x))(r),
 "",
)
result
                    
                  

Solving the challenge of Build Alphabet Staircase Shape with R

R solution 1 for Build Alphabet Staircase Shape, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
path = "Excel/627 Alphabets Staircase_2.xlsx"
test = read_excel(path, range = "A2:BA53", col_names = F)
al = LETTERS
M = matrix(NA , nrow = 52, ncol = 53)
for (i in 1:26) {
 indices = list(c(2*i - 1, 2*i - 1 ), c(2*i - 1, 2*i), c(2*i - 1, 2*i + 1), c(2*i, 2*i + 1))
 for (index in indices) {
 M[index[1], index[2]] = al[i]
 }
}
M = as.data.frame(M)
names(test) = names(M)
all(M == test, na.rm = T)
# [1] TRUE
                    
                  

Solving the challenge of Build Alphabet Staircase Shape with Excel VBA

Excel VBA solution 1 for Build Alphabet Staircase Shape, proposed by Md. Zohurul Islam:
Sub ExcelBIExcelChallenge627()
 Application.ScreenUpdating = False
 Dim nx, x, k, j
 Dim rngA As Range
 Dim rngB As Range
 
 nx = 26
 j = 2
 k = 1
 'Loop 01
 For x = 1 To nx
 Set rngA = Range(Cells(j, k), Cells(j, k + 2))
 Set rngB = rngA.Cells(3).Offset(1, 0)
 rngA.Value = Chr(x + 64)
 rngB.Value = Chr(x + 64)
 k = k + 2
 j = j + 2
 Next x
 
'adjust col width
Range("A:BA").ColumnWidth = 2
Range("A1").Select
Application.ScreenUpdating = True
End Sub
                    
                  

&&&

Leave a Reply