超级广场雨


11

Scream™冬季特卖活动已经开始,您只是在狂奔极简动作游戏Super Square。玩完游戏后,您会意识到,要么游戏太难了,要么真的很糟糕。特别是,这种“雨”模式似乎每次都会让您受益……

在此处输入图片说明

沮丧的是,您决定给自己一个不同的挑战:用ASCII艺术画雨图!

输入值

输入是一个单个正整数n,表示通过STDIN或函数参数指定的模式大小。

输出量

输出为指定大小的降雨模式,以字符串形式返回或通过STDOUT打印。整个图像之前或之后的前导或尾随空格都可以。此外,图像不必齐平到屏幕左侧,但必须清晰可辨。

这里是n = 10

 ...................
| ----------------- |
|  ...............  |
| | ------------- | |
| |  ...........  | |
| | | --------- | | |
| | |  .......  | | |
| | | | ----- | | | |
| | | |  ...  | | | |
| | | | | - | | | | |
| | | | |   | | | | |
| | | | | - | | | | |
| | | |  ...  | | | |
| | | | ----- | | | |
| | |  .......  | | |
| | | --------- | | |
| |  ...........  | |
| | ------------- | |
|  ...............  |
| ----------------- |
 ...................

这里是n = 5

 --------- 
  .......  
 | ----- | 
 |  ...  | 
 | | - | | 
 | |   | | 
 | | - | | 
 |  ...  | 
 | ----- | 
  .......  
 --------- 

最后,这是n = 1(最里面的两堵墙):

 - 

 - 

结构(为了更加清晰)

游戏区域分为两对象限,如下所示:

 AAAAAAAAA
B AAAAAAA B
BB AAAAA BB
BBB AAA BBB
BBBB A BBBB
BBBBB BBBBB
BBBB A BBBB
BBB AAA BBB
BB AAAAA BB
B AAAAAAA B
 AAAAAAAAA

上/下象限应在以连字符表示的水平墙-和带点阴影的间隙之间交替.。左/右象限应在空间和以管道表示的垂直墙之间交替|。主对角线为空,应始终填充空格。

大小的降雨模式n2n围墙,上/下象限的墙最靠近中心,而当我们远离中心时,围墙在象限之间交替。

计分

这是代码高尔夫球,因此,最少字节的代码将获胜。


4
这个游戏...我知道你在说什么。直到我击败它,我一生都偷了40个小时。^^
ThreeFx 2014年

Answers:


3

CJam,93 87 78 61 59字节

ri:K_+){K" |"*KKI-z:I-I2%:L+<SL>\+_W%L'-'.?I2*Ig-*@I0=>N}fI

n通过STDIN 取值

几个例子:

1
 - 

 - 
2
 ... 
| - |
|   |
| - |
 ... 
5
 --------- 
  .......  
 | ----- | 
 |  ...  | 
 | | - | | 
 | |   | | 
 | | - | | 
 |  ...  | 
 | ----- | 
  .......  
 --------- 
10
 ................... 
| ----------------- |
|  ...............  |
| | ------------- | |
| |  ...........  | |
| | | --------- | | |
| | |  .......  | | |
| | | | ----- | | | |
| | | |  ...  | | | |
| | | | | - | | | | |
| | | | |   | | | | |
| | | | | - | | | | |
| | | |  ...  | | | |
| | | | ----- | | | |
| | |  .......  | | |
| | | --------- | | |
| |  ...........  | |
| | ------------- | |
|  ...............  |
| ----------------- |
 ................... 

这可以打很多球,明天我会做第一件事。

在这里在线尝试


5

Haskell 150字节

我意识到这不会赢,只是想发布我的第一个代码高尔夫:D

q n=putStr$unlines$iterate(\l->let[a,b]=if l!!0!!1=='-'then"|."else" -";c=[a:s++[a]|s<-l];t=' ':[b|x<-l!!0]++" "in t:c++[t])[" - ","   "," - "]!!(n-1)

通过加载到GHCi并调用q n其中n的大小来使用。

一些例子:

*Main> q 1
 - 

 - 
*Main> q 2
 ... 
| - |
|   |
| - |
 ... 
*Main> q 5
 --------- 
  .......  
 | ----- | 
 |  ...  | 
 | | - | | 
 | |   | | 
 | | - | | 
 |  ...  | 
 | ----- | 
  .......  
 --------- 
*Main> q 10
 ................... 
| ----------------- |
|  ...............  |
| | ------------- | |
| |  ...........  | |
| | | --------- | | |
| | |  .......  | | |
| | | | ----- | | | |
| | | |  ...  | | | |
| | | | | - | | | | |
| | | | |   | | | | |
| | | | | - | | | | |
| | | |  ...  | | | |
| | | | ----- | | | |
| | |  .......  | | |
| | | --------- | | |
| |  ...........  | |
| | ------------- | |
|  ...............  |
| ----------------- |
 ................... 

有人可能会做得更好,对于Haskell来说我还很陌生。


6
不用担心获胜。;)获胜者是CJam和Pyth。打其他语言打高尔夫球就是要打败同一个“重量级”学生,并学习一些新的语言晦涩特征。欢迎来到PPCG!
Martin Ender 2014年

3

Python中,204198,191个字节

r=lambda a,b,d=' ':d.join((a,b,a[::-1]))
def f(s,i,n):d=[r(s[:i],'.-'[(n-i)%2]*((n-i)*2-1))];return i==n and[r(s,' '*(2*(i%2)+1),'')]or d+f(s,i+1,n)+d
g=lambda n:'\n'.join(f('| '*(n/2),0,n))

“ r”是一个实用程序函数,它使用可选的定界符来写成由反射的“ a”包围的“ b”(是,lambda参数可以具有默认值)。“ f”是递归的,为每个级别生成边和中间部分。“ g”是rain函数,可以用整数调用该函数以返回所请求的文本。


我只是意识到我忘记了允许返回字符串的函数,这些函数通常是我允许的(已经在其中进行了编辑)。您仍然可以通过删除空格并将第4、5行放在一行
上来

通过一点短路评估,您可以将其降低到190 :) 链接
Sp3000

抱歉,我因意外而拒绝了你。如果您编辑,我可以取消。
nutki 2014年

1

Perl 5:74个字节(73个代码+ -p

#!perl -p
s/.*/ /;$a=qw(- .)[$|--]x
s/.+/$"$&$"/g,s/^|\z/ $a 
/g,$"^="\\"for($_)x$&

在输入上获取参数(适当功能所需的行尾字符):

$ perl rain.pl <<<"3"
 ----- 
  ...  
 | - | 
 |   | 
 | - | 
  ...  
 ----- 

取消高尔夫:

                         # Read the input line into $_ (-p)
s/.*/ /;                 # Replace the input with a space (plus the original eol), saves the parameter in $&
for(($_)x$&) {           # Iterate $& times without affecting $_
  $c=s/.+/$"$&$"/g;      # Add $" (initially space) at the start and the end of each line, stores number of lines in $c
  $a=("-",".")[$|--]x$c; # Set $a to $c times minus or dot using magic $| (which iterates over 1 and 0 on decrement)
  s/^|\z/ $a \n/g;       # Equivalent to $_=" $a \n$_ $a \n"
  $"^="\\";              # Alternate $" between space and bar using the string xor 
}
                         # Print $_ (-p)
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.