金字塔计划否定


13

在我的语言Pyramid Scheme中,有一个稍微有趣的结构:空三角形:

^
-

如果不提供任何参数,则返回0。要1使用此构造生成,可以使用以下代码:

   ^
  /!\
 ^---
 -

这只是传递0给求反函数。我们可以继续否定这个结果:

 ^
/!\
---^
  /!\
 ^---
 -

得出0。又一个否定给出:

   ^
  /!\
 ^---
/!\
---^
  /!\
 ^---
 -

挑战

给定的整数Ñ ≥1,输出空金字塔被否定Ñ在所描述的方式倍。

测试用例

input
output

1
   ^
  /!\
 ^---
 -

2
 ^
/!\
---^
  /!\
 ^---
 -

3
   ^
  /!\
 ^---
/!\
---^
  /!\
 ^---
 -

6
 ^
/!\
---^
  /!\
 ^---
/!\
---^
  /!\
 ^---
/!\
---^
  /!\
 ^---
 -

通过这里的否定,我想您是说按位补码(~)?
user202729 '11

@ user202729不,我的意思是定期否定。
科纳·奥布莱恩

因此是C / C ++ !not)。
user202729

@ user202729是的。尽管这意味着与问题相切
Conor O'Brien

1
/!\ 警告!/!\我到处都看到警告三角形!
RedClover

Answers:


7

木炭,17字节

FN«↙^→/!\¶³‖T»↓^-

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

FN«

循环进行适当数量的取反。

↙^→/!\¶³

打印否定功能。(³扩展为---。)

‖T

反映画布。

»↓^-

在循环末尾,打印空三角形。


仅供参考,空三角形-代替了_
Conor O'Brien

@ ConorO'Brien感谢您指出!我确实认为它看起来不太正确,但是无法将手指放在上面……
Neil

4

Python 2,94个字节

i=input();print i%2*2*" "+" ^"
while i:print['/!\\\n---^','  /!\\\n ^---'][i%2];i-=1
print" -"

在线尝试!

尝试打高尔夫球... 3 print句话似乎很多余。


2

JavaScript(ES6),77 74字节

n=>(s=`^
  /!\\
 ^---`,n%2?`   `+s:` ^`)+`
/!\\
---${s}`.repeat(n/2)+`
 -`

尝试一下:




1

Java 8,104字节

n->{String r=n%2>0?"   ^\n":" ^\n";for(;n-->0;r+=n%2<1?"  /!\\\n ^---\n":"/!\\\n---^\n");return r+" -";}

说明:

在这里尝试。

n->{                       // Method with integer parameter and String return-type
  String r=                //  Result-String, starting at:
           n%2>0?          //  If the input is odd:
            "   ^\n"       //   Start the result at "   ^" + new-line
           :               //  Else (the input is even):
            " ^\n";        //   Start the result at " ^" + new-line
  for(;n-->0;              //  Loop the input amount of times
    r+=n%2<1?              //   If the current row is even:
        "  /!\\\n ^---\n"  //    Append the result-String with "  /!\" + new-line
                           //                                  " ^---" + new-line
       :                   //   Else (the current row is odd):
        "/!\\\n---^\n"     //    Append the result-String with "/!\" + new-line
                           //                                  "---^" + new-line
  );                       //  End of loop
  return r                 //  Return the result-String
          +" -";           //   + " -"
}                          // End of method








0

Python 3,167字节

def f(n):
	g=[[" "]*5for _ in'  '*-~n];a=["^","/!\\","---"]
	for i in range(n):
		for r,R in zip(a,g[i*2:]):R[(i-n)%2*2+(r>"]"):]=r
	g[-2][1]="^";g[-1][1]="-";return g

在线尝试!

Xcoder先生-4字节
,Jonathan Frech 先生-1字节


' '*2*n可以是' '*n(那里有两个空格,但是eugh ... SE markdown),然后' '*n+' '可以替换' '*-~n168个字节
Xcoder先生17年

@ Mr.Xcoder太棒了,谢谢!
HyperNeutrino

我认为r=="^"可以r>"]"
乔纳森·弗雷希

@JonathanFrech看来是这样,谢谢!
HyperNeutrino
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.