Gambarlah rumah ASCII

25

Ini adalah jendela:

---
| |
---

Mari kita tambahkan beberapa dinding |. Letakkan dua ruang di kedua sisinya sehingga jendela memiliki banyak ruang.

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

Sekarang mari kita tambahkan atap dan langit-langit. Untuk menjaga jendela di tengah ruangan, mari tambahkan satu baris lagi di atasnya dan di bawahnya.

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

Sekarang, tambahkan saja atap. Letakkan tebasan sejauh mungkin, dan backslash sejauh mungkin, dan kami memiliki ini:

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

Kemudian gerakkan tebasan ke atas dan ke kanan. Pindahkan backslash ke atas dan kiri:

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

Ulangi sampai kedua garis miring bertemu, lalu tambahkan tanda bintang tempat mereka bertemu:

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

Dan kamu selesai! Ini adalah rumah 1x1. rumah 2x2 akan terlihat seperti ini:

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

dan rumah 3x2:

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

Tantangan

Anda harus menulis program lengkap yang membutuhkan dua bilangan bulat, x dan y, dan mencetak rumah yang luasnya X kamar dan tinggi Y kamar. Program Anda harus dapat menangani rumah hingga 10x10. IO dapat dalam format apa pun yang masuk akal. Ruang tambahan pada setiap baris diizinkan, dan satu baris tambahan tambahan diizinkan.

Jawaban terpendek dalam byte menang.

DJMcMayhem
sumber

Jawaban:

12

Vim 122 , 89 penekanan tombol

"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*

Cobalah online!

Saya telah meningkatkan keterampilan vim-golf saya secara signifikan sejak saya memposting jawaban ini, jadi saya memutuskan untuk kembali dan menulis semua ini dari awal. Disimpan tiga puluh tiga byte dalam proses!

Input diasumsikan berada pada dua baris terpisah, sehingga buffer terlihat seperti ini sebelum Anda mulai mengetik:

3
4

Saya punya penjelasan yang sangat terperinci, tetapi saya tidak ingin menulisnya lagi dari awal ...> _ <Periksa riwayat revisi jika Anda masih ingin melihatnya.

DJMcMayhem
sumber
9

Python 3.6 (pra-rilis), 221 210 203 byte

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))

Membaca 2 bilangan bulat (dipisahkan oleh koma) dari stdin, mencetak rumah ke stdout.

Versi yang dapat dibaca:

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))
kubah
sumber
2
Fitur 3.6.0a0 apa yang digunakan ini? Hanya f'{name}'pemformatan string?
kucing
@tac: hanya f-string , ya
vaultah
1
Bagaimana Anda menginstal 3.6? Saya sudah menunggu-nunggu f-string, tetapi tidak tahu bagaimana cara menginstalnya sendiri (sekali lagi, dukungan Cygwin tidak bagus)
Sp3000
@ Sp3000: Saya membuatnya dari sumber
vaultah
@ Sp3000 Python 3.3+ tidak akan dibangun di atas Cygwin.
Mego
7

Python 2, 190 181 byte

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]

Cukup yakin ada banyak hal untuk golf, terutama windows, tapi ini sesuatu untuk saat ini. Input lebar dan tinggi dipisahkan koma, mis 1,2.

Penjelasan cepat dan kasar:

                *          <--- 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
Sp3000
sumber
3

JavaScript (ES6), 292 270 238 215 200 byte

Terima kasih @Neil untuk membantu mengurangi ini!

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`|
`)

Panggil sebagai: F(a)(b)

Bangun atap, lalu rakit rumah inti dengan pengulangan tali berlapis.

Mwr247
sumber
Ketika saya melihat jawaban Anda, saya merenungkan apakah Anda seharusnya menggunakan join`|\n` dan sekarang saya berharap saya telah berkomentar pada saat itu. Itu akan menjadi alasan yang baik untuk menambahkan komentar parsial saya yang menyarankan Anda menggunakan 9*apada titik tertentu, yang saya tidak pernah kirimkan karena terlalu pendek.
Neil
Formula Anda 4*a-1terlihat salah, saya pikir seharusnya begitu 4*a, ini akan menghemat 4 byte.
Neil
m-i-1menjadi --m. 9*a-amenjadi 8*a.
Neil
1
Sekarang, Anda tidak benar-benar menggunakan templat apa pun di string Anda, dan Anda bisa melakukan `` *\n${[...Array(m)].map(...).join\ n }\n`` tetapi Anda dapat melakukannya dengan lebih baik dan bergabung dengan string sebelum dan sesudah pada saat yang sama: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`))
Neil
1
Shave off satu byte lagi dengan `/${p(i*2+1)}\\‌`.
Neil
3

C ++, 282 byte, memperbaiki masalah dengan entri sebelumnya:

#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;}

Keluaran:

        *
       / \
      /   \
     /     \
    /       \
   /         \
  /           \
 /             \
/               \
-----------------
|       |       |
|  ---  |  ---  |
|  | |  |  | |  |
|  ---  |  ---  |
|       |       |
|-------|-------|
|       |       |
|  ---  |  ---  |
|  | |  |  | |  |
|  ---  |  ---  |
|       |       |
-----------------
Dave si Sax
sumber
3

Ruby, Rev B 165 byte

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+?|}

menggunakan satu loop dan beberapa trik golf lainnya.

Ruby, Rev A 179 byte

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

Tidak disatukan

  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 -
Level River St
sumber
Saya pikir Anda dapat menjatuhkan salah satu garis miring terbalik di string, yaitu | \-'.
Sp3000
@ Sp3000 Tidak berhasil, terima kasih. Saya kira \-tidak berarti apa-apa sebagai urutan melarikan diri, jadi \-hanya diurai sebagai 2 karakter. Maka tentu saja -memiliki makna khusus untuk tr, jadi kita perlu string ' \-'untuk windows untuk melarikan diri -(pemetaan C-> ruang, B-> -dan A-> -karena tidak ada lagi karakter yang tersisa.) Untuk lantai, kita hanya memiliki string '-'dan dalam hal ini trtampaknya senang menafsirkannya hanya sebagai karakter literal daripada karakter khusus, menugaskan C = B = A = '-'Semua itu adalah hal yang sulit untuk mulai bekerja. Saya yakin masih ada lagi golf yang akan dilakukan, akan diedit nanti.
Level River St
2

C ++, 258 Bytes Di Sini

#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;}

Hasil:

                                        *                                        
                                       / \                                       
                                      /   \                                      
                                     /     \                                     
                                    /       \                                    
                                   /         \                                   
                                  /           \                                  
                                 /             \                                 
                                /               \                                
                               /                 \                               
                              /                   \                              
                             /                     \                             
                            /                       \                            
                           /                         \                           
                          /                           \                          
                         /                             \                         
                        /                               \                        
                       /                                 \                       
                      /                                   \                      
                     /                                     \                     
                    /                                       \                    
                   /                                         \                   
                  /                                           \                  
                 /                                             \                 
                /                                               \                
               /                                                 \               
              /                                                   \              
             /                                                     \             
            /                                                       \            
           /                                                         \           
          /                                                           \          
         /                                                             \         
        /                                                               \        
       /                                                                 \       
      /                                                                   \      
     /                                                                     \     
    /                                                                       \    
   /                                                                         \   
  /                                                                           \  
 /                                                                             \ 
/                                                                               \
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |       |
---------------------------------------------------------------------------------
Johan du Toit
sumber
1
Ini tidak cocok dengan gambar OP. Lapangan tingkat lebih tinggi, dan dalam gambar OP hanya lantai atas dan bawah adalah garis padat -. Lantai-lantai antara dihancurkan dengan|
Level River St
@steveverrill Terima kasih telah menunjukkan hal itu, saya membuat kesalahan yang sama persis dalam kiriman saya sendiri. fp .
DJMcMayhem
2

C #, 361 353 byte

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;}

Program Lengkap:

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;
    }
}
DW.com
sumber
Bagus, beberapa tips umum yang berlaku di sini: Anda dapat menyimpan beberapa karakter dengan melihat lebih dekat beberapa for-loop Anda ( s=""dapat dimasukkan ke dalam for (j) loop (pertimbangkan j-->0untuk kondisinya juga, dan i++<hdalam loop terakhir), i=0dapat dipindahkan keluar dari for loop ke dalam deklarasi, menyimpan byte. Anda juga dapat menyimpan byte dengan menggunakan kembali string kosong yang ditetapkan (sekali mditugaskan, Anda dapat menetapkan o=mmenyimpan "". Ganti juga membutuhkan string, sehingga Anda dapat gunakan qbukan Anda ' ', dan tidak perlu untuk ruang setelah >saat menyatakan r. Hal-hal kecil;)
VisualMelon
Terkadang hal-hal kecillah yang membuat perbedaan. Terima kasih: D
DW.com
1

VBA, 284 byte

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

Fungsi Ganti adalah alat yang rapi untuk membuat banyak salinan dengan cara yang sayangnya tidak diinginkan fungsi String.

Meminta efek terbaik di jendela Immediate editor VBA: ?H(8,8)misalnya.

?H(8,8)
                                *
                               / \
                              /   \
                             /     \
                            /       \
                           /         \
                          /           \
                         /             \
                        /               \
                       /                 \
                      /                   \
                     /                     \
                    /                       \
                   /                         \
                  /                           \
                 /                             \
                /                               \
               /                                 \
              /                                   \
             /                                     \
            /                                       \
           /                                         \
          /                                           \
         /                                             \
        /                                               \
       /                                                 \
      /                                                   \
     /                                                     \
    /                                                       \
   /                                                         \
  /                                                           \
 /                                                             \
/                                                               \
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
|       |       |       |       |       |       |       |       |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |  | |  |
|  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |  ---  |
|       |       |       |       |       |       |       |       |
-----------------------------------------------------------------
Joffan
sumber