Home » Draw ASCII Style House

Draw ASCII Style House

Draw an ASCII house as given.

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

Solving the challenge of Draw ASCII Style House with Excel

Excel solution 1 for Draw ASCII Style House, proposed by Bo Rydobon 🇹🇭:
=MAKEARRAY(17,
    15,
    LAMBDA(r,
    c,
    REPT("#",
    OR(IF(
        r<8,
        ABS(
            c-8
        )15))))
Excel solution 2 for Draw ASCII Style House, proposed by John V.:
=MAKEARRAY(17,
    15,
    LAMBDA(r,
    c,
    REPT("#",
    OR(IF(
        r<8,
        ABS(
            c-8
        )8,
    (r<12)*(c={4,
    6})+(c={9;12})),
    (r=9)*(c={5;10;11}),
    (r=11)*(c=5),
    AND(
        r=16,
        c<>{1;15}
    ),
    r=17))))
Excel solution 3 for Draw ASCII Style House, proposed by Julian Poeltl:
=MAKEARRAY(17,
    15,
    LAMBDA(A,
    B,
    IF((A=17)+(((B=2)+(B=14))*(A>7))+(((B>2)*(B<14))*(A=16))+((A+B>8)*(A+B<(8+A*2))*(A<8))+((A>8)*(A<12)*((B=4)+(B=6)))+((B=5)*((A=9)+(A=11)))+((A=9)*((B=10)+(B=11)))+(((B=12)+(B=9))*(A>8)),
    "#",
    "")))
Excel solution 4 for Draw ASCII Style House, proposed by Timothée BLIOT:
=MAKEARRAY(
    17,
    15,
    LAMBDA(
        x,
        y,
        IF(
            OR(
                x=17,
                AND(
                    x=16,
                    y>1,
                    y<15
                ),
                AND(
                    OR(
                        y=2,
                        y=14
                    ),
                    x>6
                ),
                AND(
                    x<8,
                    8-xy
                ),
                AND(
                    OR(
                        y=12,
                        y=9
                    ),
                    x>8
                ),
                 AND(
                     x=9,
                     y>8,
                     y<12
                 ),
                AND(
                    x>8,
                    x<12,
                    y>3,
                    y<7,
                    NOT(
                        AND(
                            x=10,
                            y=5
                        )
                    )
                )
            ),
            "#",
            ""
        )
    )
)
Excel solution 5 for Draw ASCII Style House, proposed by ferhat CK:
=IFNA(LET(a,
    MAKEARRAY(11,
    15,
    LAMBDA(x,
    y,
    IFS((x=1)*(y>1)*(y<15),
    "#",
    (x=3)*(OR(
        y={4,
        5,
        6,
        9,
        10,
        11,
        12}
    )),
    "#",
    (x=4)*(OR(
        y={4,
        6,
        9,
        12}
    )),
    "#",
    (x=5)*(OR(
        y={4,
        5,
        6,
        9,
        12}
    )),
    "#",
    (x=6)*(OR(
        y={9,
        12}
    )),
    "#",
    (OR(
        x={7,
        8,
        9,
        10}
    ))*(OR(
        y={9,
        12}
    )),
    "#",
    x=11,
    "#",
    (x=10)*(AND(
        y>1,
        y<15
    )),
    "#",
    (y=2)+(y=14),
    "#"))),
    b,
    MAKEARRAY(6,
    14,
    LAMBDA(x,
    y,
    IF((y<8+x)*(y>8-x),
    "#",
    ""))),
    VSTACK(
        b,
        a
    )),
    "")

Solving the challenge of Draw ASCII Style House with Python

Python solution 1 for Draw ASCII Style House, proposed by Konrad Gryczan, PhD:
import pandas as pd
import numpy as np
path = "567  ASCII House.xlsx"
test = pd.read_excel(path, usecols="C:Q", skiprows=1, nrows=17, header=None).fillna("").values
M = np.full((17, 15), "", dtype=str)
for i in range(7):
 M[i, (7 - i):(7 + i + 1)] = "#"
M[16, :] = "#"
for i in range(7, 16):
 M[i, [1, 13]] = "#"
M[15, 1:14] = "#"
M[8:11, [3, 5]] = "#"
M[[8, 10], 4] = "#"
M[8:16, 8] = "#"
M[8, 9:11] = "#"
M[8:16, 11] = "#"
print(pd.DataFrame(M))
print((M == test).all()) # True
                    
                  

Solving the challenge of Draw ASCII Style House with Python in Excel

Python in Excel solution 1 for Draw ASCII Style House, proposed by Alejandro Campos:
H = [[" " for _ in range(15)] for _ in range(17)]
for i in range(7):
 for j in range(7 - i, 8 + i):
 H[i][j] = "#"
for i in range(7, 16):
 H[i][1] = "#"
 H[i][13] = "#"
for j in range(1, 14):
 H[15][j] = "#"
H[16] = ["#"] * 15
for i in range(8, 11):
 H[i][3] = "#"
 H[i][5] = "#"
for i in [8, 10]:
 H[i][4] = "#"
for i in range(8, 16):
 H[i][8] = "#"
for j in range(9, 11):
 H[8][j] = "#"
for i in range(8, 16):
 H[i][11] = "#"
df = pd.DataFrame(H)
df
                    
                  

Solving the challenge of Draw ASCII Style House with R

R solution 1 for Draw ASCII Style House, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
path = "Excel/567 ASCII House.xlsx"
test = read_excel(path, range = "C2:Q18", col_names = F) %>%
 replace(is.na(.), "") %>% as.matrix()
M = matrix("", nrow = 17, ncol = 15)
for (i in 1:7) {
 M[i, (8 - i + 1):(8 + i - 1)] = "#"
}
M[17, ] = "#"
for (i in 8:16) {
 M[i, c(2, 14)] = "#"
}
M[16, -c(1, 15)] = "#"
M[9:11, c(4,6)] = "#"
M[c(9, 11), 5] = "#"
M[9:16, 9] = "#"
M[9, 10:11] = "#"
M[9:16, 12] = "#"
 
all.equal(M, test, check.attributes = F) # TRUE
as.data.frame(M)
                    
                  

Solving the challenge of Draw ASCII Style House with Excel VBA

Excel VBA solution 1 for Draw ASCII Style House, proposed by Md. Zohurul Islam:
Sub ExcelBI_ExcelChallenge567()
 'draw an ascii house
 Dim x As Long, y As Variant
 Dim rng As Range
 Dim a As Range, b As Range
 Range("C18:Q18") = "#"
 Range("D8:P8") = "#"
 Range("D9:D17") = "#"
 Range("E17:O17") = "#"
 Range("P9:P17") = "#"
 Range("K10:K16") = "#"
 Range("N10:N16") = "#"
 Range("L10:M10") = "#"
 Range("F10:F12") = "#"
 Range("H10:H12") = "#"
 Range("G10") = "#"
 Range("G12") = "#"
 
 y = 0
 'loop to create upper triangle
 For x = 1 To 6
 Set a = Cells(x + 1, 10).Offset(0, -y)
 Set b = Cells(x + 1, 10).Offset(0, y)
 Set rng = Range(a, b)
 'rng.Select
 rng = "#"
 y = y + 1
 Next x
End Sub
                    
                  

&&&

Leave a Reply