让我们画Triforce


29

三角力量是在一个虚构的神器传说塞尔达,由代表力量,智慧和勇气三个相同外观的等边三角形。当三个部分最终结合在一起时,传奇中的几款游戏都包含了动画。

这项挑战的目的是绘制具有简化动画效果的单个2D帧,其中三角形的给定宽度以及零件之间的给定间距。

输入值

输入由两个整数组成:宽度和间距值。小号0w1s0

输出量

必须根据以下规格绘制框架:

         /\
        /  \____________ this part is horizontally centered
       /    \
      /______\
                    \___ s empty lines
                    /
   /\          /\
  /  \        /  \______ w+1 backslashes
 /    \      /    \
/______\    /______\
                \_______ 2w underscores
        |__|
          \_____________ 2s spaces

在上面的示例中,我们有和。s = 2w=3s=2

更多例子

s = 0w=1,:s=0

   /\   
  /__\  
 /\  /\ 
/__\/__\

s = 0w=2,:s=0

     /\     
    /  \    
   /____\   
  /\    /\  
 /  \  /  \ 
/____\/____\

s = 3w=3,:s=3

          /\          
         /  \         
        /    \        
       /______\       



   /\            /\   
  /  \          /  \  
 /    \        /    \ 
/______\      /______\

s = 1w=4,:s=1

          /\          
         /  \         
        /    \        
       /      \       
      /________\      

    /\          /\    
   /  \        /  \   
  /    \      /    \  
 /      \    /      \ 
/________\  /________\

规则

  • 每行尾随空格是可选的。
  • 每行上都不允许有多余的前导空格。
  • 您可以输出一条额外的前导换行符和/或一条额外的尾随换行符。
  • 这是

Answers:


10

Python 2中197个 194 169 167 155 144字节

w,s=input()
l=['']*(2*-~w+s)
for i in range(-~w):W=w-i;b='/'+'_ '[i<w]*2*i+'\\';l[i::w-~s]=' '*(w+s-~W)+b,' '*W+b+'  '*(W+s)+b
print'\n'.join(l)

在线尝试!


已保存:

  • -3个字节,感谢Xcoder先生

8

木炭,25字节

←×_N↗⊕θ‖M≔⁺⊕θNηCη±η‖BO⊗⊕θ

在线尝试!链接是详细版本的代码。说明:

←×_N

输入w并绘制w _s。

↗⊕θ

w+1 /s。

‖M

反射以完成第一个三角形。

≔⁺⊕θNη

输入s并计算左三角形和中间三角形之间的偏移量。

Cη±η

将左三角形复制到中间。

‖BO⊗⊕θ

围绕中间三角形反射以完成三叉戟。


嗯,检查一下这个数学。这可能是25个字符,但是是50到65 个字节(分别取决于您使用的是UTF-16还是UTF-8表示形式)。
Stuart P. Bentley '18年

我的错; 显然,木炭和画布具有自己的字符映射,对我来说似乎有点愚蠢(如果您要使用任意符号,为什么不使用现有选择),但是无论如何。
Stuart P. Bentley '18年

@ StuartP.Bentley这个网站的重点是高尔夫计划的规模。许多语言(除了Canvas和Charcoal之外,还有很多其他语言)选择每字节使用全部8位,因为这是一种接近最大高尔夫程度的好方法。漂亮的unicode只是为了使代码更易于读写(您可以尝试通过编写字节码在C中进行编程;我们也是人类)
dzaima

8

Python 2中127个 124字节

w,s=input()
n=2*-~w+s
while n:n-=1;I=w-n+(n>w)*(w-~s);print' '*n+('  '*(n+s)).join(['/'+I*2*' _'[I>=w]+'\\'][I>w:]*-~(n<=w))

在线尝试!


7

画布20 19 16 字节

+├:⁸╵\L_×;∔║ω╋║↕

在这里尝试!

说明:

+├                s + w + 2
  :               duplicated (for both X & Y)
   ⁸╵\            w+1 sized diagonal
      L_×         "_"*width of the diagonal
         ;∔       prepended before the diagonal
           ║      palindromize that
            ω     and push the argument of ║ (aka the unpalindromized version)
             ╋    overlap the upside down half-triangle over the upside down triangle at (s+w+2; s+w+2)
              ║   and palindromize the whole thing
               ↕  reverse everything vertically

注意:在此过程中,我修复了代码中的一个错误,如果没有该修复,则为18个字节


就像Neil的答案一样,它可以是16个字符,但是用Unicode术语来说,它可以是32个字节或44个字节,具体取决于您使用的UTF。(我认为它可以在旧的单字节字符集(例如代码页437)中表示,但是那里没有ω或so,因此在我看来您必须使用Unicode转换格式。)
Stuart P.本特利

@ StuartP.Bentley Canvas使用自定义代码页,如我的帖子标题中所链接。木炭的github Wiki也包含其代码页。在PPCG上已达成共识,如果有代码页/转换器对其进行备份,则可以用Unicode格式的答案进行回答。
dzaima

Tcsh,好的(尽管在您使用任意转换器的时候,在我看来,您最好还是用全名的语言编写并测量已编译的VM字节码指令长度)。
Stuart P. Bentley '18

@ StuartP.Bentley检查木炭答案链接-它包含人类可读的代码!(所以是的,有2次翻译:p)这里的人确实将汇编评分作为机器代码来回答,因此也没有理由在VM中回答
dzaima

7

[R 225224214211,208个字节

function(w,s){M=matrix
C=cbind
h=w+1
k=C(apply(m<-diag(h)*60,1,rev)/4,m)
k[row(k)==h&!k]=63
z=rbind(C(a<-M(0,h,h+s),k,a),M(0,s,h*4+2*s),C(k,M(0,h,2*s),k))
z[]=intToUtf8(z+32,T)
apply(z,1,cat,sep='','
')
rm()}

在线尝试!

  • -1个字节,感谢Giuseppe
  • 变更方法后的-10个字节
  • -3字节展开ASCII码
  • -3字节感谢JayCe

由于找不到任何要添加的内容...我只是重命名了变量,并且我还建议另一种静默返回的途径...我对TBH并不完全满意。将继续搜索!TIO
JayCe

哦,等待... if(F)0肯定可以接受,并节省一个字节。甚至更好的rm()是3个字节。
JayCe

q()根据此meta
JayCe

@JayCe:使用rm()的绝妙技巧!
digEmAll

4

帕斯卡(FPC)296264字节

const A='/';B='\';var w,s,i:word;u:string;begin read(w,s);u:=StringOfChar('_',2*w);for i:=1to w do writeln(A:w+3+s+w-i,B:i*2-1);writeln(A:w+2+s,u,B);for i:=1to s do writeln;for i:=1to w do writeln(A:w+2-i,B:i*2-1,A:2*(s+w-i)+3,B:i*2-1);write(A,u,B,A:2*s+1,u,B)end.

在线尝试!


4

Python 2中256 248 240 228 199 195字节

较长的程序,但方法略有不同:

f,b,o='/\ '
O=o*2
w,s=input()
l=f+'__'*w+b
a=l+O*s+l
m=n=[]
p=lambda g:(len(a)-len(g))/2*o+g
for i in range(w):m=m+[p(f+O*i+b)];t=f+O*i+b;n+=p(t+O*(w-i+s)+t),
print'\n'.join(m+[p(l)]+[o]*s+n+[a])

在线尝试!


由于忽略了结尾的空格,节省了很多字节,并合并了@ovs的一些技巧,
通过更早定义一个变量可以节省更多


我明天必须解决此问题(它可以工作,但我可以做得更好)
micsthepick '18




那是从两个开始的副产品
micsthepick '18


2

视网膜0.8.2,141字节

\d+
$* 
(?=( *),( *))
¶$1/$`$`\$1$2$2$1/$`$`\
T` `\_`/ *\\(?=.*,)
s`¶(.*),( *)
$1¶$.2$*¶$1
\G(( *)/(  |__)*\\)\2(  )*\1 *¶
$2 $#3$* $#4$* $1¶

在线尝试!注意:输出中有一些尾随空格。说明:

\d+
$* 

将输入转换为空格。(第二行以空格结尾。)

(?=( *),( *))
¶$1/$`$`\$1$2$2$1/$`$`\

以适当的间距创建底部两个三角形的边。

T` `\_`/ *\\(?=.*,)

填写三角形的底边。

s`¶(.*),( *)
$1¶$.2$*¶$1

用适当的垂直间距复制三角形。

\G(( *)/(  |__)*\\)\2(  )*\1 *¶
$2 $#3$* $#4$* $1¶

将上部三角形转换为单个居中三角形。


2

C(GCC),404个 389字节

#define p(x)putchar(x);
#define F for
W;S;i;a=32;b=47;c=92;f(w,s){W=w,S=s;F(;w;--w){F(i=W+w+s+1;i--;)p(a)p(b)F(i=w*2;i++-2*W;)p(a)p(c)p(10)}F(i=W+s+1;i--;)p(a)p(b)F(i=0;i++-2*W;)p(95)p(c)F(;s--+1;)p(10)F(w=W;w;--w){F(i=w;i--;)p(a)p(b)F(i=w*2;i++-2*W;)p(a)p(c)F(i=w*2+S*2;i--;)p(a)p(b)F(i=w*2;i++-2*W;)p(a)p(c)p(10)}p(b)F(i=0;i++-2*W;)p(95)p(c)F(i=S*2;i--;)p(a)p(b)F(i=0;i++-2*W;)p(95)p(c)}

在线尝试!

Rodolvertice的 -14个字节

通过修复循环变量减量来获得-1个字节

划掉404几乎还是404

取消高尔夫:

#define p(x)putchar(x); // save 7 bytes per putchar call (+24, -182)
#define F for // save 2 bytes per for loop (+14, -28)
int W, S, i; // W is w backup, S is s backup, i is an counter variable;
int a = ' '; // save 1 byte per space printed (+5, -8) (use a instead of 32)
int b = '/'; // save 1 byte per slash printed (+5, -6) (use b instead of 47)
int c = '\\'; // save 1 byte per backslash printed (+5, -6) (use c instead of 92)
// This isn't worth it for '\n' (-5, +3) (10), or '_' (-5, +3) (95)
int f(int w, int s) {
    W = w; // Backup w and s, as we will modify them later, 
    S = s; // but will need their original values
    for(; w != 0; --w) { // Top triangle (not the bottom line)
        for(i = W+w+s+1; i != 0; --i) // leading spaces
            putchar(' ');
        putchar('/'); // left side of triangle
        for(i = 2*w; i != 2*W; ++i) // inner spaces
            putchar(' ');
        putchar('\\'); // right side of triangle
        putchar('\n'); // newline
    }
    for(i = W+s+1; i != 0; --i)
        putchar(' '); // leading spaces for the bottom line
    putchar('/'); // left side
    for(i = 0; i != 2*W; ++i)
        putchar('_'); // the bottom line
    putchar('\\'); // right side
    for(; s-- + 1 != 0;)
        putchar('\n'); // newline after the bottom line and S empty lines
    for(w = W; w != 0; --w) { // Bottom triangles
        for(i = w; i != 0; --i)
            putchar(' '); // leading spaces
        putchar('/'); // left of left triangle
        for(i = w*2; i != 2*W; ++i)
            putchar(' '); // inside of left triangle
        putchar('\\'); // right of left triangle
        for(i = w*2+S*2; i != 0; --i)
            putchar(' '); // spaces between left and right triangles
        putchar('/');
        for(i = w*2; i != 2*W; ++i)
            putchar(' '); // inside of right triangle
        putchar('\\'); // right of right triangle
        putchar('\n'); // newline
    }
    putchar('//'); // left of left
    for(i = 0; i != 2*W; ++i)
        putchar('_'); // bottom of left triangle
    putchar('\\'); // right of left
    for(i = S*2; i != 0; --i)
        putchar(' '); // space between triangles
    putchar('/'); // left of right
    for(i = 0; i != 2*W; ++i)
        putchar('_'); // bottom of left triangle
    putchar('\\'); // right of right
}


1
#define f为节省一些字节
rodolphito

你不能吗#define p putchar
RK。

1
@RK。如果我这样做了,那么对于(+26,-6)= +20字节,我将不得不使用p(x);代替p(x)。扩展宏时,将包括分号。
pizzapant184 '18


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.