Home » Render a Lamp in ASCII

Render a Lamp in ASCII

Make an ASCII lamp.

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

Solving the challenge of Render a Lamp in ASCII with Excel

Excel solution 1 for Render a Lamp in ASCII, proposed by Bo Rydobon 🇹🇭:
=MAKEARRAY(9,21,LAMBDA(r,c,REPT("x",ABS(c-11)5,17-r,(r+1)/3))))
Excel solution 2 for Render a Lamp in ASCII, proposed by Rick Rothstein:
=MAKEARRAY(
    9,
    21,
    LAMBDA(
        r,
        c,
        IF(
            ABS(
                c-11
            )
Excel solution 3 for Render a Lamp in ASCII, proposed by John V.:
=LET(
    s,
    SEQUENCE,
    r,
    s(
        9
    ),
    REPT(
        "x",
        ABS(
            s(
                ,
                21
            )-11
        )
Excel solution 4 for Render a Lamp in ASCII, proposed by Julian Poeltl:
=MAKEARRAY(9,
    21,
    LAMBDA(A,
    B,
    IFS((A<3)*(B=11),
    "x",
    (A>2)*(A<6)*(B>9)*(B<13),
    "x",
    (A>5)*(B>A-6)*(B<28-A),
    "x",
    1,
    "")))
Excel solution 5 for Render a Lamp in ASCII, proposed by Timothée BLIOT:
=MAKEARRAY(
    9,
    21,
    LAMBDA(
        x,
        y,
        IF(
            OR(
                y=11,
                AND(
                    y>9,
                    y<13,
                    x>2
                ),
                AND(
                    x>5,
                    y+6>x,
                    28-y>x
                )
            ),
            "x",
            ""
        )
    )
)
Excel solution 6 for Render a Lamp in ASCII, proposed by Sunny Baggu:
=LET(
 _a, ABS(SEQUENCE(, 21) - 11),
 _b, {0; 0; 1; 1; 1; 10; 9; 8; 7},
 IF(_a + N("Happy Diwali🪔") <= _b, "x", "")
)
Excel solution 7 for Render a Lamp in ASCII, proposed by Andy Heybruch:
=MAKEARRAY(9,21,LAMBDA(_r,_c,IFERROR(IFS(
_c=11,"x",
AND(ABS(11-_c)=1,_r>2),"x",
AND(_r>5,(_r-6+ABS(11-_c))<11),"x"),"")))
Excel solution 8 for Render a Lamp in ASCII, proposed by Eddy Wijaya:
=LET(
    
    a,
    9,
    
    b,
    21,
    
    MAKEARRAY(
        a,
        b,
        LAMBDA(
            r,
            c,
            LET(
                
                f,
                LAMBDA(
                    x,
                    SEQUENCE(
                        x
                    )
                ),
                
                m,
                MEDIAN(
                    SEQUENCE(
                        b
                    )
                ),
                
                IFNA(
                    IFS(
                        c=m,
                        "*",
                        
                        AND(
                            OR(
                                c=m-1,
                                c=m+1
                            ),
                            r>=3,
                            r<=5
                        ),
                        "*",
                        
                        r=6,
                        "*",
                        
                        AND(
                            r=7,
                            c<>1,
                            c<>b
                        ),
                        "*",
                        
                        AND(
                            r=8,
                            c<>f(
                                2
                            ),
                            c<>21-f(
                                2
                            )+1
                        ),
                        "*",
                        
                        AND(
                            r=9,
                            c<>f(
                                3
                            ),
                            c<>21-f(
                                3
                            )+1
                        ),
                        "*"
                    ),
                    ""
                )
            )
        )
    )
)
Excel solution 9 for Render a Lamp in ASCII, proposed by Philippe Brillault:
=IF(ABS(SEQUENCE(,21)-INT(21/2)-1)<={0;0;1;1;1;10;9;8;7},"X","")
Excel solution 10 for Render a Lamp in ASCII, proposed by Songglod P.:
=MAKEARRAY(9,21,LAMBDA(r,c,IFERROR(IFS(OR(c=10,AND(c>8,c<12,r>2)),"x",AND(r>6,c<4),IF(r-c<6,"x",""),AND(r>6,c>18),IF(r+c-11<17,"x",""),r>5,"x"),"")))
Excel solution 11 for Render a Lamp in ASCII, proposed by Michael D. Newby:
=LET(x,
    CHAR(
        SEQUENCE(
            255,
            1,
            1,
            1
        )
    ),
    FILTER(x,
    (CODE(
        x
    )>10)*(CLEAN(
        TRIM(
        x
    )
    )<>"")))
I like 164 (¤):
=MAKEARRAY(
    9,
    21,
    LAMBDA(
        r,
        c,
        REPT(
            charcode,
            ABS(
                c-11
            )5,
                17-r,
                r/2.5
            )
        )
    )
)

Solving the challenge of Render a Lamp in ASCII with Python

Python solution 1 for Render a Lamp in ASCII, proposed by Konrad Gryczan, PhD:
import pandas as pd
import numpy as np
path = "577 Make ASCII Lamp.xlsx"
test = pd.read_excel(path, header=None, usecols="C:W", skiprows=1, nrows=10).fillna("").to_numpy()
def centered(matrix, row, how_many):
 pad = (matrix.shape[1] - how_many) // 2
 matrix[row, pad:pad + how_many] = "x"
 return matrix
M = np.full((10, 21), "", dtype=object)
for i in range(1, 10):
 how_many = 1 if i < 3 else 3 if i < 6 else 21 - (i - 6) * 2
 M = centered(M, i, how_many)
print(np.array_equal(M, test)) # True
                    
                  

Solving the challenge of Render a Lamp in ASCII with R

R solution 1 for Render a Lamp in ASCII, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
path = "Excel/577 Make ASCII Lamp.xlsx"
test = read_excel(path, range = "B2:X11", col_names = F) %>% as.matrix()
test[is.na(test)] <- ""
centered = function(matrix, row, how_many) {
 pad <- (ncol(matrix) - how_many) %/% 2
 matrix[row, ] <- c(rep("", pad), rep("x", how_many), rep("", ncol(matrix) - how_many - pad))
 matrix
}
M = matrix("", nrow = 10, ncol = 23)
M <- reduce(2:3, ~centered(.x, .y, 1), .init = M)
M <- reduce(4:6, ~centered(.x, .y, 3), .init = M)
M <- reduce(7:10, ~centered(.x, .y, 21 - (.y - 7) * 2), .init = M)
all.equal(M, test, check.attributes = F)
#> [1] TRUE
                    
                  

Solving the challenge of Render a Lamp in ASCII with Excel VBA

Excel VBA solution 1 for Render a Lamp in ASCII, proposed by Md. Zohurul Islam:
Sub ExcelBI_ExcelChallenge577()
 Dim r, x, y
 Dim rng As Range
 
 Range("M3:M7") = "x"
 Range("L5:L7") = "x"
 Range("N5:N7") = "x"
 x = 3
 y = 23
 
 For r = 1 To 4
 Set rng = Range(Cells(r + 7, x), Cells(r + 7, y))
 rng = "x"
 x = x + 1
 y = y - 1
 Next r
'column adjustment
Range("B:W").ColumnWidth = 1#
End Sub
                    
                  

&&&

Leave a Reply