ASCII Art射箭箭


16

编写一个程序或函数,该程序或函数需要一个正整数,并打印或返回根据输入比例缩放的射箭箭头的ASCII艺术插图。

如果输入是1输出

  /\
 /  \
 \__/
  ||
  ||
  ||
  ||
  ||
  ||
  ||
  ||
 /||\
/ || \
/ || \
//  \\
/    \

如果输入是2输出

     /\
    /  \
   /    \
  /      \
  \      /
   \____/
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
   /|  |\
  / |  | \
 /  |  |  \
/   |  |   \
/   |  |   \
/   |__|   \
/  /    \  \
/ /      \ \
//        \\
/          \

如果输入是3输出

        /\
       /  \
      /    \
     /      \
    /        \
   /          \
   \          /
    \        /
     \______/
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
     /|    |\
    / |    | \
   /  |    |  \
  /   |    |   \
 /    |    |    \
/     |    |     \
/     |    |     \
/     |    |     \
/     |____|     \
/    /      \    \
/   /        \   \
/  /          \  \
/ /            \ \
//              \\
/                \

如果输入是4输出

           /\
          /  \
         /    \
        /      \
       /        \
      /          \
     /            \
    /              \
    \              /
     \            /
      \          /
       \________/
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
       /|      |\
      / |      | \
     /  |      |  \
    /   |      |   \
   /    |      |    \
  /     |      |     \
 /      |      |      \
/       |      |       \
/       |      |       \
/       |      |       \
/       |      |       \
/       |______|       \
/      /        \      \
/     /          \     \
/    /            \    \
/   /              \   \
/  /                \  \
/ /                  \ \
//                    \\
/                      \

对于较大的输入数字,该模式继续进行-箭头相应放大。

请注意,对于任何输入N:

  • 箭头是一个五边形,在底部具有2×N下划线,从底部延伸的每侧上都有N个斜线,在形成箭头尖端的两侧上有2×N个斜线。
  • 轴(包括抓取中的部分)由两条垂直条的11×N行组成,两条垂直条之间的间隔为2×(N-1)个空格。最后一行带有下划线而不是空格。
  • 碎片围绕着轴的下部3×N线。两行2×N的斜线从轴的两侧斜向下延伸,并与垂直的斜线列相连。
  • 完整的箭头是16×N行高和6×N个字符宽。

在输出中,箭头尖端前不应有空行,最多只能有一个尾随的换行符。

任何输出线都不应有不必要的前导空格(拼写的左边缘应尽可能最左侧),但任何一行都可以具有任意数量的尾随空格。

以字节为单位的最短提交获胜。


是否有最大输入大小?
Downgoat

1
@vihan号。尽管您可以假设数字不会溢出您的内存/整数。
加尔文的爱好2015年

我们应该担心文字换行吗?对于N> = 14,终端上的默认窗口大小使我的箭头看起来不像箭头。
kevinsa5

@ kevinsa5不,不用担心。
加尔文的爱好2015年

Answers:


2

Pyth,149 147 146 144 146

编辑2015-9-23:有一个错误,已修复为2个字节。可能可以缩短时间,我现在没有时间。

对于Pyth答案来说似乎仍然太久了。

M*tGHK*11Q=Y*3QA" /"jbC+R*yQG+_Js[ms[*dGHgt-YdG\_gKG\_)tQs[gQGHgyQG\_*K\|)ms[*+QdGH*y-tQdG\\*+*8QydGHgYGH)Qms[*++KQdGHgYGH)tQ+g*13QG*hYH)mXd"\/")J

说明(几乎是最新的)

我基本上会生成箭头的转置,因为它的线格式要简单得多。另外,我只生成一半,然后反转它以节省很多字节。

M*tGH                                                       g(a,b) = (a - 1) * b
A" /"                                                       G = " ", H = "/"
              ms[...)tQ                                     N-1 lines inside body
                       s[...)                               1 line of edge of body
                             ms[...)Q                       N lines of tip + fin
                                     m...Q                  N-1 lines of fin
                                          +...              1 line of edge of fin
            s[                                )             flatten the maps to it
           J                                                save to J
          _                                                 reverse
                                                       J    another copy (unreversed)
                                               mXd"\/")     swap "\" and "/" on each line
         +                                                  add to other half
   +R*yQG                                                   add 2*N spaces to each line
  C                                                         transpose
jb                                                          join by newline

m                             tQ       map d over 0...N-2
 s[                          )         concatenate
   *dG                                 d spaces
      H                                "/"
          =Y*3Q                        save 3*N to Y
       gt-     dG                      3*N-d-2 spaces
                 \_                    "_"
                    K*11Q              save 11*N to K
                   g     G             11*N-1 spaces
                          \_           "_"

s[              )                      concatenate
  gQG                                  N-1 spaces
     H                                 "/"
      gyQG                             2*N-1 spaces
          \_                           "_"
            *K\|                       11*N pipes

m                               Q      map d over 0...N-1
 s[                            )       concatenate
   *+QdG                               N+d spaces
        H                              "/"
         *y-tQdG                       2*(N-d-1) spaces
                \\                     "\"
                  *+*8QydG             8*N+2*d spaces
                          H            "/"
                           gYG         3*N-1 spaces
                              H        "/"

m               tQ                     map d over 0...N-2
 +++                                   concatenate
    *++KQdG                            12*N+d spaces
           H                           "/"
            gYG                        3*N-1 spaces
               H                       "/"

+                                      concatenate
 g*13QG                                13*N-1 spaces
       *hYH                            3*N+1 slashes

3

Perl,298个字节

for$y(0..($w=<>)*16-1){$r=$w*3;for$x(0..$w*6-1){$z=$x<$r?$x:$w*6-$x-1,$_.=$z==$r-$y-1&&$y<$w*2||!$z&&$y>=$w*13-1||($z==$w*16-1-$y||$z==$w*13-1-$y)&&$z<$w*2?$x<$r?'/':'\\':$z==$y-$w&&$y>=$w*2&&$y<$r?$x<$r?'\\':'/':$z==$r-$w&&$y>=$r&&$y<$w*14?'|':$z>=$r-$w&&($y==$r-1||$y==$w*14-1)?_:$"}$_.=$/}print

多行:

for$y(0..($w=<>)*16-1){$r=$w*3;  # read input and loop over rows
    for$x(0..$w*6-1){  # loop over columns

        # flip x on right side of arrow:
        $z=$x<$r?$x:$w*6-$x-1;

        # slashes on fletching and tip of arrowhead:
        $_.=$z==$r-$y-1&&$y<$w*2||!$z&&$y>=$w*13-1||($z==$w*16-1-$y||$z==$w*13-1-$y)&&$z<$w*2?$x<$r?'/':'\\':

        # slashes on underside of arrowhead:
        $z==$y-$w&&$y>=$w*2&&$y<$r?$x<$r?'\\':'/':

        # vertical bars on side of shaft:
        $z==$r-$w&&$y>=$r&&$y<$w*14?'|':

        # underscores on base of arrowhead and shaft:
        $z>=$r-$w&&($y==$r-1||$y==$w*14-1)?_:$"
   }
   $_.=$/  # add newline at end of each row
}
print  # print out string

输出:

2
     /\     
    /  \    
   /    \   
  /      \  
  \      /  
   \____/   
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
    |  |    
   /|  |\   
  / |  | \  
 /  |  |  \ 
/   |  |   \
/   |  |   \
/   |__|   \
/  /    \  \
/ /      \ \
//        \\
/          \

感谢Dom Hastings帮助我节省了5个(并计数)字节


1
嗨,samgak,可以通过将$w=<>声明移至第一次使用的方式来节省一些字节,for$y(0..($w=<>)*16-1){并且可以删除很多括号(有些确实会改变输出,但我认为您还是要解决这些问题!)。同样,您'_'也可以只是文字_。希望有帮助!
Dom Hastings

2

朱莉娅452字节

这个答案不是很启发,而且我还没有打出明显的眼光。我希望这是其他人能打败的分数。

function R(c,x,y,e,f,n)
for i=1:n
a[y,x]=c
x+=e
y+=f
end
end
function f(n::Int)
global a=fill(' ',16n,6n)
F='/'
B='\\'
q=3n+1
r=2n+1
R(F,3n,1,-1,1,2n)
R(B,q,1,1,1,2n)
R(B,n+1,r,1,1,n)
R(F,5n,r,-1,1,n)
R('_',r,3n,1,0,2n)
R('|',r,q,0,1,11n)
R('|',4n,q,0,1,11n)
R('_',r+1,14n,1,0,r-3)
R(F,2n,11n+1,-1,1,2n)
R(B,4n+1,11n+1,1,1,2n)
R(F,1,13n,0,1,3n)
R(B,6n,13n,0,1,3n)
R(F,2n,14n+1,-1,1,2n)
R(B,4n+1,14n+1,1,1,2n)
for b = 1:16n
println(join(a[b,:]))
end
end

试试看:

julia> f(1)
  /\                          
 /  \                         
 \__/                         
  ||                          
  ||                          
  ||                          
  ||                          
  ||                          
  ||                          
  ||                          
  ||                          
 /||\                         
/ || \                        
/ || \                        
//  \\                        
/    \

松散

# Repeat a character through array a from (x,y) -> (x+n*dx,y+n*dy)
function R(a::Array{Char,2},c::Char, x::Int, y::Int, dx::Int, dy::Int, n::Int)
    for i = 1:n
        a[y,x] = c
        x += dx
        y += dy
    end
end

function arrow(n::Int)
    a = fill(' ',16n,6n)
    # upper left of head
    R(a,'/',3n,1,-1,1,2n)
    # upper right of head
    R(a,'\\',3n+1,1,1,1,2n)
    # lower left of head
    R(a,'\\',n+1,2n+1,1,1,n)
    # lower right of head
    R(a,'/',5n,2n+1,-1,1,n)
    # bottom of head
    R(a,'_',2n+1,3n,1,0,2n)
    # shaft
    R(a,'|',2n+1,3n+1,0,1,11n)
    R(a,'|',4n,3n+1,0,1,11n)
    R(a,'_',2n+2,14n,1,0,2n-2)
    # upper fletching edges
    R(a,'/',2n,11n + 1,-1,1,2n)
    R(a,'\\',4n+1,11n+1,1,1,2n)
    # fletching sides
    R(a,'/',1,13n,0,1,3n)
    R(a,'\\',6n,13n,0,1,3n)
    # lower fletching edges
    R(a,'/',2n,14n + 1,-1,1,2n)
    R(a,'\\',4n+1,14n+1,1,1,2n)
    for r = 1:16n
        println(join(a[r,:]))
    end
end

2

红宝石233

->n{(16*n).times{|i|j=i/n
m=n*3
e=' '*6*n
i%(11*n)==m-1&&e[2*n..4*n-1]=?_*2*n
j%14>2&&e[m+n-1]=e[m-n]=?|
k=(i-n)%m
k<n||j<11||(e[m+k]=?\\;e[m-1-k]=?/)
j>12&&(e[-1]=?\\;e[0]=?/)
j<3&&(e[n+l=(i-n*2)%(n*4)]=?\\;e[5*n-l-1]=?/)  
puts e}}

我曾经\用一个表达式在头部绘制所有内容的环绕式技术特别令我感到满意(同样适用于/

取消测试程序

f=->n{
  #loop line by line, 0..16*n-1
  (16*n).times{|i|

  #convenience variables
  j=i/n
  m=n*3

  #setup a string of spaces
  e=' '*6*n

  #draw the ___ at top and bottom of shaft
  i%(11*n)==m-1&&e[2*n..4*n-1]=?_*2*n
  #draw the |, overwriting the _ in the bottom corners
  j%14>2&&e[m+n-1]=e[m-n]=?|

  #draw the diagonal fletching
  k=(i-n)%m
  k<n||j<11||(e[m+k]=?\\;e[m-1-k]=?/)

  #draw the ends of the fletching (note index -1, meaning last character in string)
  j>12&&(e[-1]=?\\;e[0]=?/)

  #draw the arrow head, wrapping round with %(n*4)
  j<3&&(e[n+l=(i-n*2)%(n*4)]=?\\;e[5*n-l-1]=?/)

  #output the line  
  puts e}
}

f.call(gets.to_i)
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.