25
\$\begingroup\$

This is a window:

---
| |
---

Let's add some walls |. Put two spaces on either side of it so that the window has plenty of room.

|  ---  |
|  | |  |
|  ---  |

Now let's add a roof and a ceiling. To keep the window in the middle of the room, let's add one more row above it and below it.

---------
|       |
|  ---  |
|  | |  |
|  ---  |
|       |
---------

Now, just add a roof. Put a slash as far left as possible, and a backslash as far right as possible, and we have this:

/       \
---------
|       |
|  ---  |
|  | |  |
|  ---  |
|       |
---------

Then move the slash up one and right one. Move the backslash up one and left one:

 /     \
/       \
---------
|       |
|  ---  |
|  | |  |
|  ---  |
|       |
---------

Repeat until the two slashes meet, then add an asterisk where they meet:

    *
   / \
  /   \
 /     \
/       \
---------
|       |
|  ---  |
|  | |  |
|  ---  |
|       |
---------

And you're done! This is a 1x1 house. a 2x2 house would look like this:

        *
       / \
      /   \
     /     \
    /       \
   /         \
  /           \
 /             \
/               \
-----------------
|       |       |
|  ---  |  ---  |
|  | |  |  | |  |
|  ---  |  ---  |
|       |       |
|-------|-------|
|       |       |
|  ---  |  ---  |
|  | |  |  | |  |
|  ---  |  ---  |
|       |       |
-----------------

and a 3x2 house:

            *
           / \
          /   \
         /     \
        /       \
       /         \
      /           \
     /             \
    /               \
   /                 \
  /                   \
 /                     \
/                       \
-------------------------
|       |       |       |
|  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |
|       |       |       |
|-------|-------|-------|
|       |       |       |
|  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |
|       |       |       |
-------------------------

The challenge

You must write a full program that takes two integers, x and y, and prints a house that is X rooms wide and Y rooms tall. Your program should be able to handle houses up to 10x10. IO can be in any reasonable format. Trailing spaces on each line are allowed, and one trailing newline is allowed.

Shortest answer in bytes wins.

\$\endgroup\$

11 Answers 11

12
\$\begingroup\$

Vim 122, 89 Keystrokes

"aDJ"bD9i-<esc>Y2pVr <C-v>jr|$.Y4p3l<C-v>jljlr-jR| |<esc>{l<C-v>}d@apjdG@bp}Vr-{YPVr r/$r\qqYPllxx|P@qq@qddr*

Try it online!

I've improved my vim-golfing skills significantly since I posted this answer, so I decided to go back and write this whole thing from scratch. Saved thirty-three bytes in the process!

Input is assumed to be on two separate lines, so that the buffer looks like this before you start typing:

3
4

I had a very detailed explanation, but I don't feel like writing it all over again from the beginning... >_< Check out the revision history if you still want to see it.

\$\endgroup\$
0
8
\$\begingroup\$

Python 3.6 (pre-release), 221 210 203 bytes

x,y=eval(input())
w=8*x+1;p='-'*w+'\n'
for v in['*',*[f'/{" "*i}\\'for i in range(1,w-1,2)],p+p.join([''.join(f'{"".join([f"|{(a*3)[:3]:^7}"]*x)}|\n'for a in(*' -','| |',*'- '))]*y)+p]:print(v.center(w))

Reads 2 integers (separated by comma) from stdin, prints the house to stdout.

Readable version:

x, y = eval(input())
w = 8 * x + 1 # total width (in characters)
p = '-' * w + '\n' # floors
for v in [
    '*', # asterisk
    *[f'/{" "*i}\\' for i in range(1, w-1, 2)], # roof
    p + p.join([''.join(f'{"".join([f"|{(a*3)[:3]:^7}"]*x)}|\n' for a in (*' -','| |',*'- '))]*y) + p # rooms
]:
    print(v.center(w))
\$\endgroup\$
7
  • 2
    \$\begingroup\$ Which 3.6.0a0 feature/s does this use? Just f'{name}' string formatting? \$\endgroup\$
    – cat
    Commented Mar 2, 2016 at 17:49
  • \$\begingroup\$ @tac: only f-strings, yes \$\endgroup\$
    – vaultah
    Commented Mar 2, 2016 at 17:50
  • 1
    \$\begingroup\$ How did you install 3.6? I've been eagerly waiting for f-strings, but couldn't figure out how to install it myself (then again, Cygwin support isn't great) \$\endgroup\$
    – Sp3000
    Commented Mar 3, 2016 at 12:18
  • \$\begingroup\$ @Sp3000: I built it from source \$\endgroup\$
    – vaultah
    Commented Mar 3, 2016 at 12:53
  • \$\begingroup\$ @Sp3000 Python 3.3+ won't build on Cygwin. \$\endgroup\$
    – user45941
    Commented Mar 4, 2016 at 22:05
6
\$\begingroup\$

Python 2, 190 181 bytes

w,h=input();W=w*4
for i in range(~W,h*6+1):print['-'[i%(h*6):]*(W-~W)or['  %s  '%' -|-  - -  -|- '[~i%6::5],'-'*7][i%6<1].join('|'*-~w),' '*~i+['/%*c'%(w*8-~i*2,92),'*'][W<-i]][i<0]

Pretty sure there's much to golf, especially the windows, but here's something for now. Input width and height comma-separated, e.g. 1,2.

Quick and rough explanation:

                *          <--- i = ~W = -w*4 - 1.    <---\
               / \         <--\ i = -W = -w*4             | Preceding spaces
              /   \           |                           | are calculated
             /     \          |                           | the same way
            /       \      <--/ i = -1                <---/
   /--->    ---------      <--- i = 0                 
   |        |       |      <--\ i = 1                 <---\
Check       |  ---  |         |                           | Calculate inner string
i%(h*6)     |  | |  |         |                           | and use to join '|'s
is zero     |  ---  |         |                           | (ditto with |-------|)
   |        |       |      <--/ i = h*6 - 1           <---/
   \--->    ---------      <--- i = h*6

            ^       ^
            \-------/

          W-~W = w*8 + 1
\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6), 292 270 238 215 200 bytes

Thanks @Neil for helping trim this down!

a=>b=>[(p=(c,d=' ')=>d.repeat(c))(m=4*a)+'*',...[...Array(m)].map((c,i)=>p(--m)+`/${p(i*2+1)}\\‌`),y=p(8*a+1,'-')].join`
`+p(b,`
`+[x=p(a,'|'+p(7)),w=p(a,'|  ---  '),p(a,'|  | |  '),w,x,y].join`|
`)

Call as: F(a)(b)

Builds the roof, then assembles the core house with layered string repeats.

\$\endgroup\$
8
  • \$\begingroup\$ When I saw your answer I pondered whether you should have used join`|\n` and now I wish I had commented at the time. It would have been a good excuse to add to my partial comment suggesting you use 9*a at some point, which I never submitted because it was too short. \$\endgroup\$
    – Neil
    Commented Mar 3, 2016 at 0:34
  • \$\begingroup\$ Your formula 4*a-1 looks incorrect, I think it should be 4*a, this would incidentally save you 4 bytes. \$\endgroup\$
    – Neil
    Commented Mar 3, 2016 at 0:44
  • \$\begingroup\$ m-i-1 becomes --m. 9*a-a becomes 8*a. \$\endgroup\$
    – Neil
    Commented Mar 3, 2016 at 0:46
  • 1
    \$\begingroup\$ Now, you're not actually using any templates in your strings, and you could have done `` *\n${[...Array(m)].map(...).join\n}\n `` but you can go one better and join the string before and after at the same time: a=>b=>(p=(c,d=' ')=>d.repeat(c),[p(m=4*a)+`*`,...[...Array(m)].map((c,i)=>p(--m)+'/'+p(i*2+1)+'\\'),y=p(8*a+1,'-')].join`\n`+p(b,`\n`+[x=p(a,'| '),w=p(a,'| --- '),p(a,'| | | '),w,x,y].join`|\n`)) \$\endgroup\$
    – Neil
    Commented Mar 3, 2016 at 0:48
  • 1
    \$\begingroup\$ Shave off one more byte with `/${p(i*2+1)}\\‌`. \$\endgroup\$
    – Neil
    Commented Mar 3, 2016 at 8:58
2
\$\begingroup\$

C++, 258 Bytes Test Here

#include<cstdio>
int main(){for(int r=10,c=10,x,y,q,u,h=c*4,w=h*2,i=0;i<h+r*8+2;i++)for(q=0;q<w+2;q++)x=q%8,y=i%8,u=(i-(h+1))%8,putchar(q==w+1?10:i<=h?!i&&q==h?42:i==h-q?47:i==q-h?92:32:!u||(u==3||u==5)&&x>2&&x<6?45:!x||u==4&&(x==3||x==5)?124:32);return 0;}

Result:

                                        *                                        
                                       / \                                       
                                      /   \                                      
                                     /     \                                     
                                    /       \                                    
                                   /         \                                   
                                  /           \                                  
                                 /             \                                 
                                /               \                                
                               /                 \                               
                              /                   \                              
                             /                     \                             
                            /                       \                            
                           /                         \                           
                          /                           \                          
                         /                             \                         
                        /                               \                        
                       /                                 \                       
                      /                                   \                      
                     /                                     \                     
                    /                                       \                    
                   /                                         \                   
                  /                                           \                  
                 /                                             \                 
                /                                               \                
               /                                                 \               
              /                                                   \              
             /                                                     \             
            /                                                       \            
           /                                                         \           
          /                                                           \          
         /                                                             \         
        /                                                               \        
       /                                                                 \       
      /                                                                   \      
     /                                                                     \     
    /                                                                       \    
   /                                                                         \   
  /                                                                           \  
 /                                                                             \ 
/                                                                               \
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
\$\endgroup\$
3
  • 1
    \$\begingroup\$ This does not match OP's image. Pitch of storeys is higher, and in OP's image only the top and bottom floors are solid lines of -. The intermediate floors are broken up with | \$\endgroup\$ Commented Mar 4, 2016 at 14:01
  • \$\begingroup\$ @steveverrill Thanks for pointing that out, I made the exact same mistake in my own submission. fp. \$\endgroup\$
    – DJMcMayhem
    Commented Mar 4, 2016 at 18:55
  • \$\begingroup\$ 238 bytes \$\endgroup\$
    – ceilingcat
    Commented Jun 12, 2021 at 18:13
2
\$\begingroup\$

C++, 282 bytes, fixes the problems with the previous entry:

#include<cstdio>
int main(){for(int r=2,c=2,x,y,q,u,h=c*4,w=h*2,i=0;i<h+r*6+2;i++)for(q=0;q<w+2;q++)x=q%8,y=i%8,u=(i-h-1)%6,putchar(q==w+1?10:i<=h?!i&&q==h?42:i==h-q?47:i==q-h?92:32:!u&&x||!u&&(i<h+2||i==h+r*6+1)||(u==2||u==4)&&x>2&&x<6?45:!x||u==3&&(x==3||x==5)?124:32);return 0;}

Output:

        *
       / \
      /   \
     /     \
    /       \
   /         \
  /           \
 /             \
/               \
-----------------
|       |       |
|  ---  |  ---  |
|  | |  |  | |  |
|  ---  |  ---  |
|       |       |
|-------|-------|
|       |       |
|  ---  |  ---  |
|  | |  |  | |  |
|  ---  |  ---  |
|       |       |
-----------------
\$\endgroup\$
2
\$\begingroup\$

Ruby, Rev B 165 bytes

w=1-2*r=-4*x=gets.to_i
puts (r-1..h=6*gets.to_i).map{|n|n<0?(n<r ??*:?/+' '*(w+n*2)+?\\).center(w):n%h<1?(?-*w):'|CCBABCC'.tr('CBA','   | \-'[1222>>n%6*2&6,3])*x+?|}

uses a single loop and several other golfing tricks.

Ruby, Rev A 179 bytes

w=1+8*x=gets.to_i
y=gets.to_i
b=(0..x*4).map{|n|(n<1??*:?/+' '*(n*2-1)+?\\).center(w)}
a=(2..y*6).map{|n|('|CCBABCC'.tr('CBA','   | \\-'[4888>>n%6*2&6,3]))*x+?|}
puts b,s=?-*w,a,s

Ungolfed

  x=gets.to_i
  y=gets.to_i

  w=x*8+1                                  #calculate width of house

  b=(0..x*4).map{|n|                       #design a roof line by line
    (n<1??*:?/+' '*(n*2-1)+?\\).center(w)  #first line is *, second line is /[spaces]\
  }                                        #centre correctly to the width of the house by padding

  a=(2..y*6).map{|n|                       #design a front facade line by line
    ('|CCBABCC'.                           #template for each row
      tr('CBA','   | \\-'[4888>>n%6*2&6,3])#substitute CBA for 3 characters from the string according to magic number 4888
    )*x+?|                                 #we need x copies, finishing with a |
  }

  puts b,s=?-*w,a,s                        #print a roof, a line of -, a facade and another line of -
\$\endgroup\$
2
  • \$\begingroup\$ I think you can drop one of the backslashes in the string, i.e. | \-'. \$\endgroup\$
    – Sp3000
    Commented Mar 3, 2016 at 10:32
  • \$\begingroup\$ @Sp3000 That does work, thanks. I guess \- doesn't mean anything as an escape sequence, so the \- is just parsed as 2 characters. Then of course - has a special meaning to tr, so we need the string ' \-' for the windows to escape the - (mapping C-> space, B->- and A->- as there are no more characters left.) For the floors, we have only the string '-' and in this case tr seems happy to interpret it just as a literal rather than a special character, assigning C=B=A = '-' All in all it was a tricky thing to get working. I'm sure there's more golfing to do, will edit later. \$\endgroup\$ Commented Mar 3, 2016 at 11:04
1
\$\begingroup\$

C#, 361 353 bytes

string b(int w,int h){string m="",s,f,o=m,x,y,n="\n",p="|",q=" ";int i=0,v=w*4;Func<int,string,string>r=(j,c)=>{for(s="";j-->0;)s+=c;return s;};m+=r(v,q)+"*\n";for(;i<v;)m+=r(v-i-1,q)+'/'+r(i++*2+1,q)+"\\\n";f=r(w*8+1,"-");m+=f;x=n+r(w,p+r(7,q))+p;y=n+r(w,"|  ---  ")+p;o=x+y+n+r(w,"|  | |  ")+p+y+x;for(i=1;i++<h;)m+=o+x.Replace(q,'-');return m+o+n+f;}

Full Program:

using System;
class House
{
    static int Main()
    {
        var x = new House();
        Console.WriteLine(x.b(1,1));
        Console.WriteLine();
        Console.WriteLine(x.b(2,2));
        Console.WriteLine();
        Console.WriteLine(x.b(2,3));
        Console.WriteLine();
        Console.WriteLine(x.b(9,9));
        Console.WriteLine();
        Console.Read();
        Console.WriteLine(x.b(10, 10)); // Looks broken because Bash to small
        Console.Read();
        return 0;
    }

    string b(int w,int h){string m="",s,f,o=m,x,y,n="\n",p="|",q=" ";int i=0,v=w*4;Func<int,string,string>r=(j,c)=>{for(s="";j-->0;)s+=c;return s;};m+=r(v,q)+"*\n";for(;i<v;)m+=r(v-i-1,q)+'/'+r(i++*2+1,q)+"\\\n";f=r(w*8+1,"-");m+=f;x=n+r(w,p+r(7,q))+p;y=n+r(w,"|  ---  ")+p;o=x+y+n+r(w,"|  | |  ")+p+y+x;for(i=1;i++<h;)m+=o+x.Replace(q,'-');return m+o+n+f;}

    // Without extra vars
    string b1(int w, int h)
    {
        string m = "", s, f, o = m, x, y;
        int i = 0, v = w*4;
        Func<int,string,string> r = (j,c) => {
            for(s = ""; j-->0;) s += c;
            return s;
        };
        /// Roof
        m += r(v, " ") + "*\n";
        for (; i < v;) m += r(v - i - 1, " ") + '/' + r(i++ * 2 + 1, " ") + "\\\n";
        /// Ceiling
        f = r(w * 8 + 1, "-");
        m += f;
        /// Room
        x = "\n" + r(w, "|" + r(7, " ")) + "|";
        y = "\n" + r(w, "|  ---  ") + "|";
        o = x + y + "\n" + r(w, "|  | |  ") + "|" + y + x;
        for (i = 1; i++ < h;) m += o + x.Replace(' ','-');
        /// Floor
        return m + o + "\n" + f;
    }

    string build(int width, int height)
    {
        // House, tempStr, floor, room, x/y = room_row1/2
        string house = "", s, ceil, room = "", x, y;
        int i, v = width*4;
        Func<int,string,string> rep = (j,c) => {
            s = "";
            for(; j>0; j--) s += c;
            return s;
        };
        /// Roof
        house += rep(v, " ") + "*\n";
        for (i = 0; i < v;) {
            // LEFT Indent + '/' + Distance + '\'
            house += rep(v - i - 1, " ") + '/' + rep(i++ * 2 + 1, " ") + "\\\n";
        }
        /// Ceiling
        ceil = rep(width * 8 + 1, "-");
        house += ceil;
        /// Room
        x = "\n" + rep(width, "|" + rep(7, " ")) + "|";
        y = "\n" + rep(width, "|  ---  ") + "|";
        room = x + y + "\n" + rep(width, "|  | |  ") + "|" + y + x;
        for (i = 1; i < height; i++) {
            house += room;// + x.Replace(' ','-');
            house += "\n" + rep(width, "|" + rep(7, "-")) + "|";
        }
        /// Floor
        house += room + "\n" + ceil;
        return house;
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ Nice, couple of general tips that apply here: you can save a handful of characters by taking a closer look at some of your for-loops (s="" can be put inside the for(j) loop (consider j-->0 for the condition as well, and i++<h in the last loop), i=0 can be moved out of the for loop into the declaration saving a byte. You can also save a byte by reusing assigned empty strings (once m is assigned, you can assign o=m saving the "". Replace also takes strings, so you can use your q instead of ' ', and there is no need for the space after the > when declaring r. Small things ;) \$\endgroup\$ Commented Mar 7, 2016 at 23:00
  • \$\begingroup\$ Sometimes it's the small things that make the difference. Thanks :D \$\endgroup\$
    – DW.com
    Commented Mar 8, 2016 at 12:42
1
\$\begingroup\$

VBA, 284 bytes

Function H(W,S)
L=vbLf:H=Space(4*W)&"*"&L
For R=1 To 4*W:H=H &Space(4*W-R)&"/"&Space(2*R-1)&"\"&L:Next
J=".":P=String(W,J)&"|"&L
D=String(8*W+1,"-")&L
E=Replace(P,J,"|       ")
F=Replace(P,J,"|  ---  ")
H=H &Replace(String(S,J),J,D &E &F &Replace(P,J,"|  | |  ")&F &E)&D
End Function

The Replace function is a neat tool for making multiple copies in a way that the String function unfortunately doesn't want to.

Invoke for best effect in the Immediate window of the VBA editor: ?H(8,8) for example.

?H(8,8)
                                *
                               / \
                              /   \
                             /     \
                            /       \
                           /         \
                          /           \
                         /             \
                        /               \
                       /                 \
                      /                   \
                     /                     \
                    /                       \
                   /                         \
                  /                           \
                 /                             \
                /                               \
               /                                 \
              /                                   \
             /                                     \
            /                                       \
           /                                         \
          /                                           \
         /                                             \
        /                                               \
       /                                                 \
      /                                                   \
     /                                                     \
    /                                                       \
   /                                                         \
  /                                                           \
 /                                                             \
/                                                               \
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog Extended), 91 bytes

'*'↑⍨-1+3×w←⎕
' /'[⊖a],' ',' \'[a←∘.=⍨⍳w×3]
' |-'[2⍪⍨2⍪¯1↓⊃⍪/⎕⌿⊂1,⍨⊃,/w/⊂⍉3⊤269+⎕AV⍳'4 4#']

Try it online!

Full program, takes columns, then rows, on separate lines.

\$\endgroup\$
0
\$\begingroup\$

Vyxal, 76 bytes

4*:×꘍,(¹4*n-‹\/꘍nd›\\꘍+,)¹8*›¤-?(…\|7꘍¹*\|+…\|:2꘍2-ømṪ¹*$+…»ŀ»‛ |τ¹*\|+,,,),

Try it Online!

A. Mess.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.